gpt4 book ai didi

javascript - 按隐藏列对数据表进行排序

转载 作者:数据小太阳 更新时间:2023-10-29 03:49:56 24 4
gpt4 key购买 nike

我有 datatable,其中包含 id、firstName、lastName、phone、updated 字段。

问题: 我只向 datatable 添加了四个字段(id、firstName、lastName 和 phone)。 已更新 字段已隐藏。

问题:如何按更新字段对datatable进行排序?

我的代码:

   $('#table').dataTable({
sDom: '<"top"fi>tS',
sScrollY: ($(window).height() - 250) + "px",
bPaginate: false,
bDeferRender: true,
bAutoWidth: false,
oLanguage: {
sInfo: "Total: _TOTAL_ entities",
sEmptyTable: "No pending entities"
},
"aoColumnDefs": [
{ "iDataSort": 4, "aTargets": [ 0 ] }
],
"aoColumns": [
{ "sWidth": "10%" },
{ "sWidth": "40%" },
{ "sWidth": "30%" },
{ "sWidth": "20%" },
{ "sTitle": "updated ", "bVisible":false }
],
fnCreatedRow: function( nRow, aData, iDataIndex ) {
$(nRow).attr('id', aData[0]);
}
});

table.fnAddData([id, firstName, lastName, phone, updated]);

最佳答案

From the documentation: .

iDataSort The column index (starting from 0!) that you wish a sort to be performed upon when this column is selected for sorting. This can be used for sorting on hidden columns for example.

Default: -1 Use automatically calculated column index

Type: int

// Using aoColumnDefs
$(document).ready( function() {
$('#example').dataTable( {
"aoColumnDefs": [
{ "iDataSort": 1, "aTargets": [ 0 ] }
]
} );
} );

// Using aoColumns
$(document).ready( function() {
$('#example').dataTable( {
"aoColumns": [
{ "iDataSort": 1 },
null,
null,
null,
null
]
} );
} );

关于javascript - 按隐藏列对数据表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21430963/

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