javascript – 使用jquery数据表选择单个复选框

前端之家收集整理的这篇文章主要介绍了javascript – 使用jquery数据表选择单个复选框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
jquery数据表中,应选中单个复选框.

link工作正常.

但上面的链接是使用jquery.dataTables 1.10.16版本.我正在使用jquery.dataTables 1.9.4.

使用jquery.dataTables 1.9.4而不是jquery.dataTables 1.10.16可以实现与上面给出的示例中列出的功能相同的功能吗?

解决方法

在您提供链接的同一页面中,有许多关于使用“单一检查”选项的说明.

在列出的附件的末尾,您可以看到referanced .js文件

https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js

在您的页面中,您应该在dataTable.js之后添加文件referance.

我认为,jquery的版本并不重要.重要的文件是“dataTables.select.js”!

其次,您必须更新您的dataTable制造商代码,如下面的示例;

$(document).ready(function() {
    $('#example').DataTable( {
        columnDefs: [ {
            orderable: false,className: 'select-checkBox',targets:   0
        } ],select: {
            style:    'os',selector: 'td:first-child' // this line is the most importan!
        },order: [[ 1,'asc' ]]
    } );
} );

更新 :

为什么不尝试编写自己的选择器功能

例如;

$(document).ready(function() {
    $('#example').DataTable( {
            /// put your options here...
        } );

    $('#example').find("tr").click(function(){ CheckTheRow(this); });
} );

function CheckTheRow(tr){
    if($(tr).find("td:first").hasClass("selected")) return;

    // get the pagination row count
    var activePaginationSelected = $("#example_length").find("select").val();

    // show all rows
    $("#example_length").find("select").val(-1).trigger("change");

    // remove the prevIoUs selection mark
    $("#example").find("tr").each(function(i,a){
         $(a).find("td:first").removeClass("selected");
         $(a).find("td:first").html("");
     });

     // mark the picked row
     $(tr).find("td:first").addClass("selected");
     $(tr).find("td:first").html("<i class='fa fa-check'></i>");

     // re turn the pagination to first stuation
     $("#example_length").find("select")
                         .val(activePaginationSelected).trigger("change");

}

猜你在找的jQuery相关文章