jQuery Datatables在coulmn中插入字段值 [英] jQuery Datatables inserting a field value in a coulmn

查看:143
本文介绍了jQuery Datatables在coulmn中插入字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery数据表插件,执行以下操作,

I've a jQuery datatables plugin which does the following,

<tr>
            <th>Id</th>
            <th>Datee</th>
            <th>Delete</th>
</tr>

 $('#data').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "userlist.php",
        "aoColumns": [
            null,
            null,
            {
                "mDataProp": null,
                "sDefaultContent": '<a href="delete.php?action=activate&">DEL</a>'
            }
        ]
    } );

所以我在这里做的是我使用服务器端处理和添加数据附加列与链接删除记录。

So what i'm doing here is that i'm getting data using server side processing and adding an additionalm column with link to delete the record.

现在我想要id = <>为特定记录添加在&作为

Now I want id=<> for that particular record to be added at the end of & in a href as

a href="delete.php?action=activate&id=<<first column value> .

另外我想将MySQL日期转换为PHP日期为第二列。

Also i want to convert MySQL date to PHP date for second column.

如何做?

谢谢。

推荐答案

尝试这样:修改里卡多的答案如下:

Try this: Modify Ricardo's answer as follows:

"sDefaultContent": '<a href="delete.php?action=activate&" class="delete">DEL</a>'

$('#data').on('click', 'td .delete', function(e) {
    e.preventDefault()
    var id = $(this).closest('tr').find('td:first').html();
    var href='delete.php?action=activate&id=' + id;
//  $('a.delete', $(this)).attr('href', href);
    window.location.href = href;
});

编辑:你当表格被添加到链接的href属性时,不需要添加 id 以HTML代码呈现,以下代码将通过ajax调用 delete.php 脚本,并将 id 的值传递给那个脚本。

You don't need to have the id added to the href attribute of the link when the table is rendered in HTML. The following code will call the delete.php script via ajax and will pass the value of id to that script.

$('#data').on('click', 'td .delete', function(e) {
    e.preventDefault()
    var id = $(this).closest('tr').find('td:first').html();
    $.get("delete.php", {id:id});
});

(然后您将需要更新显示的datatable以及某种方式 - 有以下API API函数: 删除数据表的一行)。

(You will then need to update the displayed datatable as well somehow - there are API functions for this: Delete a row of a datatable).

更新:另一个选择是执行以下操作:

UPDATE: Another option is to do the following:

$("a.delete").each(function(){
    var id = $(this).closest('tr').find('td:first').html();
    var href = "delete.php?action=activate&id=" + id;
    $(this).attr('href', href);
});

这篇关于jQuery Datatables在coulmn中插入字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆