2015-11-21 88 views
0

我的數據表包含一列列。 它包括從1開始的學生排名,如果學生缺席,排名被定義爲「缺席」。 問題是排序此列說到像1,10,11,12時,...,2,20,21,......,缺席,缺席,..如何對包含值'Absent'的數據表排序列進行排序也

我的數據表初始化時

$(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,...,缺席,缺席,...

回答

0

什麼你正在尋找被稱爲「自然排序」。如果你在SO中搜索,你會發現你的答案。試試這個 Sort Array Elements (string with numbers), natural sort

+0

如何在數據表中包含這個? Datatable將該列作爲字符串,如何在那裏定義自定義排序? – anjana

+0

有一些現有的數據表插件可以進行自然排序,請參閱https://www.datatables.net/plug-ins/sorting/natural – Cyph

+0

thanks.it在我添加插件並通過給出「aoColumns」時起作用:[ 空, 空, 空, 空, 空, { 「STYPE」: 「數字」},{ 「STYPE」: 「自然」}, 空 。但是在這第三列是學生的名字,它通過給字符串類型不起作用 – anjana

相關問題