DataTable添加checkbox

省市区所属网点门店名称门店地址姓名手机号身份证号身份证正反面营业执照门店照片店内存放空间照片审核状态审核时间
    `function initDatatable() {
    datatable = $('.datatable').DataTable({
        "dom": '<"toolbar">frtip',
        "searching": false,
        "processing": false,
        "serverSide": true,
        "select": false,
        "ordering": true,
        //"aLengthMenu":[ 6, 8, 10, 20,50 ],
        "iDisplayLength": 20,
        "language": {
            "url": "${base}/assets/plugins/datatables/cn.json"
        },
        "preDrawCallback": function () {
            sublime.showLoadingbar($(".main-content"));
        },
        "drawCallback": function () {
            sublime.closeLoadingbar($(".main-content"));
        },
        "ajax": {
            "url": "${base}/platform/agent/agent/info/data",
            "type": "post",
            "data": function (d) {
                d.startAuditTime = $("#startAuditTime").val();
                d.endAuditTime = $("#endAuditTime").val();
                d.branch_name = $("#branch_name").val();
                d.audit_state = $("#audit_state").val();
                d.province_id = $("#province_id").val();
                d.city_id = $("#city_id").val();
                d.county_id = $("#county_id").val();
                $(".checkall")[0].checked = false;
            }
        },
        "order": [[13, "desc"]],
        "columns": [
            {"sClass": "text-center",
             "render": function (data, type, full, meta) {
                return '<input type="checkbox" class="checkchild"/>';
            },"bSortable": false},
            {"data": function (e) {
                if (e.province&&e.city&&e.county) {
                    return e.pro+"/"+e.cit+"/"+e.cou;
                }
                return "";
            }, "bSortable": false},
            {"data": "branch_name", "bSortable": false},
            {"data": "agent_name", "bSortable": false},
            {"data": "address", "bSortable": false},
            {"data": "username", "bSortable": false},
            {"data": "phone", "bSortable": false},
            {"data": "idcard", "bSortable": false},
            {"data": function (e) {
                if (e.idcard_pos_photo&&e.idcard_neg_photo) {
                    return "<a href='javascript:void(0)' onclick='showPicture("+e.idcard_pos_photo+","+e.idcard_neg_photo+")'>详情</a>";
                }
                return "";
            }, "bSortable": false},
            {"data": function (e) {
                if (e.licence_photo) {
                    return "<a href='javascript:void(0)' onclick='showPicture("+e.licence_photo+")'>详情</a>";
                }
                return "";
            }, "bSortable": false},
            {"data": function (e) {
                if (e.shop_photo) {
                    return "<a href='javascript:void(0)' onclick='showPicture("+e.shop_photo+")'>详情</a>";
                }
                return "";
            }, "bSortable": false},
            {"data": function (e) {
                if (e.inner_photo) {
                    return "<a href='javascript:void(0)' onclick='showPicture("+e.inner_photo+")'>详情</a>";
                }
                return "";
            }, "bSortable": false},
            {"data": function (e) {
                if (e.audit_state=="aduit_waitting") {
                    return "<span style='color:green'>待审核</span>";
                }else if(e.audit_state=="aduit_pass"){
                    return "<span style='color:blue'>正常</span>";
                }else if(e.audit_state=="aduit_close"){
                    return "<span style='color:orange'>关闭</span>";
                }else if(e.audit_state=="aduit_fail"){
                    return "<span style='color:red'>审核失败</span>";
                }else{
                    return "";
                }
            }, "bSortable": false},
            {"data": "audit_time", "bSortable": true}
        ]
    });
    datatable.on('click', 'tr', function () {
        $(this).toggleClass('selected');
        var i = datatable.row(this).index();
        var all = $(".checkchild");
        for(var j = 0 ; j < all.length; j++){
            if ( j == i ){
                var thisClass = $(this)[0].className;
                if(thisClass.indexOf('selected')>=0){
                    all[j].checked = true;
                }else{
                    all[j].checked = false;
                    $(".checkall")[0].checked = false;
                }
            }
        }
    });
}
$(".checkall").click(function () {
        var check = $(this).prop("checked");
        $(".checkchild").prop("checked", check);
        var trs = document.getElementById("tableID").getElementsByTagName("tr");
        if(check){
            for(var i=0;i<trs.length;i++){
                trs[i].setAttribute("class", "selected"); 
            }
        }else{
            for(var i=0;i<trs.length;i++){
                trs[i].setAttribute("class", ""); 
            }
        }

    });
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值