如何解决数据表 - Jquery:: 如何
在这个 jquery 数据表定义中
var table_devices = $('#table-all').DataTable({
columns: [
{ "data" : 'id'},{ "data" : "bank" },{ "data" : "account" },{ "data" : "iban" },],"columnDefs": [
{
render: function( data,type,row,Meta) {
return `<button class="btn btn-primary btn-sm table-edit-outbanks" type="button" data-id=${data} data-row-index=${Meta.row} title="Modifica"><i class="fa fa-edit"></i></button> <button class="btn btn-primary btn-sm table-remove-outbanks" type="button" data-id=${data} title="Cancella" data-toggle="modal"><i class="fa fa-trash"></i></button>`
},className: 'text-Nowrap',targets: 0,'orderable': false,},{
className: 'text-center text-Nowrap',targets: [1,2,3],}
],});
我想使用
分配表格数据function getTableData() {
$.ajax({
url: "/gettabledata/",type: 'GET',headers: { 'X-CSrftoken': csrftoken },success: function(res) {
// console.log('load',res)
tableData = res
table_devices.rows.add(tableData).draw()
},error : function(xhr,errmsg,err) {
console.log(err)
}
})
}
我想让它更通用,但如何使以下内容通用
columns: [
{ "data" : 'id'},
和
{
className: 'text-center text-Nowrap',}
我可能有不同的列,列数可能会有所不同
like targets: [1,...n]
并直接从 ajax res 传递列 obj
那我该怎么办
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。