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

VB_*_*VB_ 9 javascript jquery datatables

我有datatableid, firstName, lastName, phone, updated领域.

问题:datatable只添加了四个字段(id,firstName,lastName和phone).Updated字段是隐藏的.

问题:如何datatableupdated字段排序?

我的代码:

   $('#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]);
Run Code Online (Sandbox Code Playgroud)

sre*_*ree 8

从文档:.

iDataSort您希望在选择此列进行排序时执行排序的列索引(从0开始!).例如,这可用于对隐藏列进行排序.

Default: -1 使用自动计算的列索引

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
    ]
  } );
} );
Run Code Online (Sandbox Code Playgroud)

  • 现在肯定已经弃用了......你应该通过HTML 5使用`data-sort`.请参阅http://stackoverflow.com/a/28730668/1408137 (3认同)