【发布时间】:2014-01-29 12:20:00
【问题描述】:
我有 datatable 和 id, firstName, lastName, phone, updated 字段。
问题:我只向datatable 添加了四个字段(id、firstName、lastName 和 phone)。 Updated 字段已隐藏。
问题:如何按updated字段对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]);
【问题讨论】:
-
你想在表初始化上对其进行排序吗?
-
@dcodesmith 是的。但如果我能随时排序就好了。
-
好的,更新列在你表中的位置,我知道它是隐藏的,但它应该有索引
-
@dcodesmith by hidden 我的意思是我根本不添加它。如果我必须添加
updated列,请告诉我如何 -
@dcodesmith 我的意思是目前
table不包含任何updated字段。我不知道如何添加隐藏字段。
标签: javascript jquery datatables