在JSON中,我有一个包含数组的对象'Keys'
"keys": [
{
"key": "...",
"customer": "...",
"externalUser": null,
"name": "Administrator key 1",
"privileges": 32,
"partitionKey": "...",
"rowKey": "...",
"timestamp": "2018-11-02T03:51:27.4099037+00:00",
"eTag": "W/\"datetime'2018-11-02T03%3A51%3A27.4099037Z'\""
},
{
"key": "...",
"customer": "...",
"externalUser": null,
"name": "Administrator key 2",
"privileges": 32,
"partitionKey": "...",
"rowKey": "...",
"timestamp": "2018-11-02T03:51:27.4159094+00:00",
"eTag": "W/\"datetime'2018-11-02T03%3A51%3A27.4159094Z'\""
}
]
我要实现的是仅显示表上privileges
等于'32'
的行。
到目前为止,我可以使用rowCallback
"rowCallback": function( row, data, index ) {
if (data['privileges'] && data['privileges'] != '32') {
$(row).hide();
}
}
完整功能在这里
function fetchKeysByCustomerId(customerId){
var getKeysById = "https://..." + customerId;
var tt = $('#apiAccessKeyTable').DataTable( {
"ajax": {
"url": getKeysById,
"dataSrc": "keys"
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "key" },
{ "data": null },
{ "data": null }
],
"columnDefs": [
{ "targets":0, "searchable": false, "orderable": false}
],
"order": [[ 1, 'desc' ]],
'processing': true
} );
tt.on( 'order.dt search.dt', function () {
tt.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();
}
但这不是理想的,因为仅隐藏了行。如果我对其他列进行排序,则会弄乱表的索引列。
如何完全删除或仅根据条件渲染行?