gpt4 book ai didi

jquery - 在 jquery DataTables 中跳过一行的渲染

转载 作者:行者123 更新时间:2023-12-01 00:09:56 25 4
gpt4 key购买 nike

如果在初始化期间满足条件,我想跳过行渲染,但我不知道到底将其放置在哪里。

我应该把它放在fnCreatedRow还是fnPreDrawCallback中?
我怎样才能做到这一点?

这是我的代码:

 var users_tbl =$('#users_tbl');
users_tbl.DataTable({
"deferRender": true,
"autoWidth": false,
//for reinitialisation purpose
destroy: true,
"aLengthMenu": [[20, 40, 50, 100, -1], [20, 40, 50, 100, "All"]],
"order": [[ 0, "DESC" ]],
"ajax" : {
url : Main.Vars.host + "settings/get_users",
type : "GET",
},
"aoColumnDefs": [

{ "sWidth": "5%", "aTargets": [ 0 ] },
{ "sWidth": "20%", "aTargets": [ 1 ] },
{ "sWidth": "25%", "aTargets": [ 2 ] },
{ "sWidth": "15%", "aTargets": [ 3 ] },
{ "sWidth": "5%", "aTargets": [ 4 ] },
],
"fnCreatedRow" : function( nRow, aData, iDataIndex ){
$(nRow).addClass('item-context');

return false;
},
"fnPreDrawCallback": function( oSettings ) {
console.log(oSettings);
},
"columns": [
{
"data": "id",
},
{
"data": "username",
},
{
"render": function(data,type,row,meta) {
var owner = row.pnp_info.first_name + " " + row.pnp_info.last_name;
return owner;
}
},
{
"data": "created_on",

},
{
"render": function(data,type,row,meta) {
return row.active == 1 ? "YES" : "NO";
}
},

],

sPaginationType: "full_numbers",
});

最佳答案

对于fnCreatedRow来说已经太晚了,对于fnPreDrawCallback你最终只是取消了表格的渲染。您有两种不同的方式:

1) 清理 ajax.dataSrc 中的 JSON回调:

var table = $('#example').DataTable( {
ajax : {
url : 'test.json',
dataSrc: function(json) {
var rows = [];
for (var i=0;i<json.data.length;i++) {
//skip rows "if a condition is met"
//here just any rows except row #1
if (i>0) rows.push(json.data[i]);
}
return rows;
}
}
....
})

2) 清理 xhr 上的 JSON事件:

table.on('xhr.dt', function (e, settings, json, xhr) {
//manipulate the json directly, no return needed
//delete row #1, same as above
json.data.splice(0,1);
});

这两个示例都假设您在(简化)表单上拥有格式良好的 JSON

{
"data": [
{
"id": "2423",
"username" : "joe"
},
{
"id": "4321",
"username" : "gordon"
}
]
}

关于jquery - 在 jquery DataTables 中跳过一行的渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32168926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com