我正在使用 jQuery 数据表。我在 JSON 中得到的值很少作为数据表中的列。在其中两列中,一列只有单选按钮,一列只有复选框。我想根据复选框(如果复选框被选中,它应该首先出现)和单选按钮进行排序。我该怎么做?
最佳答案
参见 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" }
]
} );
} );
关于javascript - 基于单选按钮和复选框的数据表排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36546526/