如何对数据进行排序 table 对包含值 'Absent' 的列进行排名
how to sort data table rank column rank wise which contains value 'Absent' also
我的数据table 包含排名列。
它包括从 1 开始的学生排名,如果学生缺席,则排名定义为 'Absent'。
问题是当对该列进行排序时,它会出现 1,10,11,12,...,2,20,21,..,Absent,Absent,..
我的数据table初始化是
$(document).ready( function () {
var oTable = $('#filtertableobj').dataTable({
"iDisplayLength": 500,"aLengthMenu": [[100, 200, 500, 1000], [100, 200, 500, 1000]],
/*BEGIN Fixing the index row so they are not sorted -r2ros */
"fnDrawCallback": function ( oSettings ) {
var that = this;
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
this.$('td:first-child', {"filter":"applied"}).each( function (i)
{
that.fnUpdate( i+1, this.parentNode, 0, false, false );
} );
}
},
"aoColumnDefs": [{ "bSortable": false, "aTargets": [ 0 ] } ],
});
});
如何排序如 1,2,3,...,10,11,12,..,缺席,缺席,...
您要找的是 "natural sort"。如果您在 SO 中搜索它,您会找到答案。试试这个
Sort Array Elements (string with numbers), natural sort
我的数据table 包含排名列。 它包括从 1 开始的学生排名,如果学生缺席,则排名定义为 'Absent'。 问题是当对该列进行排序时,它会出现 1,10,11,12,...,2,20,21,..,Absent,Absent,..
我的数据table初始化是
$(document).ready( function () {
var oTable = $('#filtertableobj').dataTable({
"iDisplayLength": 500,"aLengthMenu": [[100, 200, 500, 1000], [100, 200, 500, 1000]],
/*BEGIN Fixing the index row so they are not sorted -r2ros */
"fnDrawCallback": function ( oSettings ) {
var that = this;
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
this.$('td:first-child', {"filter":"applied"}).each( function (i)
{
that.fnUpdate( i+1, this.parentNode, 0, false, false );
} );
}
},
"aoColumnDefs": [{ "bSortable": false, "aTargets": [ 0 ] } ],
});
});
如何排序如 1,2,3,...,10,11,12,..,缺席,缺席,...
您要找的是 "natural sort"。如果您在 SO 中搜索它,您会找到答案。试试这个 Sort Array Elements (string with numbers), natural sort