2016-04-11 99 views
1

我正在使用jQuery数据表。我在数据表中获取json中的很少值作为列。在其中两列中,只有一个单选按钮,一个只有复选框。我想根据复选框进行排序(例如,如果复选框已勾选,它应该先出现)和单选按钮。我怎样才能做到这一点 ?基于单选按钮和复选框的数据表排序

回答

1

请参阅Live DOM ordering示例。

/* Create an array with the values of all the checkboxes in a column */ 
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) 
{ 
    return this.api().column(col, {order:'index'}).nodes().map(function (td, i) { 
     return $('input', td).prop('checked') ? '1' : '0'; 
    }); 
} 

/* Initialise the table with the required column ordering data types */ 
$(document).ready(function() { 
    $('#example').DataTable({ 
     "columns": [ 
      { "orderDataType": "dom-checkbox" } 
     ] 
    }); 
});