javascript - 基于单选按钮和复选框的数据表排序

标签 javascript jquery datatables

我正在使用 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/

相关文章:

javascript - 为什么 redis 返回 [239, 191, 189] 响应缓冲区?

javascript - 右滑 react native 删除列表项

javascript - 以列的垂直顺序设置 tabindex

javascript - 将单元格值从表格复制到文本框

javascript - 如何在初始化时过滤 jquery 数据表

json - Ember 和数据表集成

jquery - 工具提示不适用于数据表

javascript - 在客户端上的何处存储 html 字符串以供以后插入 DOM?

javascript - Javascript 中的分段控件

javascript - 从数据属性设置 jQuery 插件选项