Javascript 基于单选按钮和复选框的数据表排序
我正在使用jQuery数据表。我在JSON中得到的数据表列值很少。在其中两列中,一列只有单选按钮,另一列只有复选框。我想根据复选框和单选按钮进行排序(比如,如果选中复选框,它应该首先出现)。我如何才能做到这一点?参见示例Javascript 基于单选按钮和复选框的数据表排序,javascript,jquery,datatables,Javascript,Jquery,Datatables,我正在使用jQuery数据表。我在JSON中得到的数据表列值很少。在其中两列中,一列只有单选按钮,另一列只有复选框。我想根据复选框和单选按钮进行排序(比如,如果选中复选框,它应该首先出现)。我如何才能做到这一点?参见示例 /* Create an array with the values of all the checkboxes in a column */ $.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, co
/* 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" }
]
} );
} );