DataTable服务器端处理添加编辑列 [英] DataTable serverside processing adding edit column

查看:187
本文介绍了DataTable服务器端处理添加编辑列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用datatable 1.10.13服务器端处理。并且我想添加一个编辑用户链接列编辑。怎么办?



我的js文件

  $('#userTable) DataTable({
processing:true,
serverSide:true,
ajax:{
type:GET,
url :,
dataSrc:data,
contentType:application / json; charset = utf-8,
dataType:json b $ bprocessData:true
},

列:[
{data:id},
{data email},
{data:},//编辑链接栏
]
});

DataTable查看php

 < table cellspacing =0id =userTableclass =display> 
< thead>
< tr>
< th class =ui-state-default> Name< / th>
< th class =ui-state-default> Email< / th>
< th class =ui-state-default> EDIT< / th>
< / tr>
< / thead>
< tbody>< / tbody>
< / table>

请指教

解决方案

你需要通过提供html的回调来定义具有回调的render属性:

 columns:[
{data:id},
{data:email},
{data:id
可搜索:false,
sortable:false,
render:function(id,type,full,meta){
return'< a href = / user / userdata /'+ id +'>< i class =fa fa-pencil>< / i>< / a>
}
},
]


I'm using datatable 1.10.13 serverside processing. And I want to add a column 'edit' with edit user link. How to do this?

My js file

$('#userTable').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "type": "GET",
        "url": "",
        "dataSrc": "data",
        "contentType": "application/json; charset=utf-8",
        "dataType": "json",
        "processData": true
    },

    "columns": [
        { "data": "id" },
        { "data": "email" },
        { "data": "" }, //edit link column
    ]
} );

DataTable view php

<table cellspacing="0" id="userTable" class="display">
    <thead>
    <tr>
        <th class="ui-state-default">Name</th>
        <th class="ui-state-default">Email</th>
        <th class="ui-state-default">EDIT</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

please advise

解决方案

you need to define the render property with the callback that how to render the column by providing the html which would be :

"columns": [
        { "data": "id" },
        { "data": "email" },
        { "data": "id",
          "searchable": false,
          "sortable": false,
          "render": function (id, type, full, meta) {
                                    return '<a href="/user/userdata/'+id+'"><i class="fa fa-pencil"></i></a>';
                                } 
        },
    ]

这篇关于DataTable服务器端处理添加编辑列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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