datatables初始化用法

var recordTable =
        $('#record_table').DataTable({
            "fnInitComplete": function () { //表格初始化完成后调用的回调方法
                if ($('#record_table .dataTables_empty').length != 0) {
                    $('#record_table .odd').children().attr("colspan", 6);
                }
            },
            bAutoWidth: false,
            "bStateSave": true,
            "aaSorting": [],
            "oLanguage": {
                "sSearch": "搜索",
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "没有记录",
                "sInfo": "从 _START_ 到 _END_ /  共 _TOTAL_ 条",
                "sInfoEmpty": "显示0条记录",
                "oPaginate": {
                    "sPrevious": "上一页",
                    "sNext": "下一页"
                }
            },
            select: {
                style: 'multi'
            },
            destroy: true,//每次重新加载
            "aoColumns": [
                { "sDefaultContent": '', "width": "5%", "bSortable": false, "sClass": "text-left" },
                { "data": 'userName', "width": "19%", "bSortable": false, "sClass": "text-left" },
                { "data": 'followTime', "width": "19%", "bSortable": false, "sClass": "text-left" },
                {
                    "data": 'certClass', "width": "19%", "bSortable": false, "sClass": "text-left",
                    "render": function (data, type, full, meta) {
                        if (data == 0)
                            return '未认证';
                        else if (data == 1) return '普通认证';
                        else if (data == 2) return '高级认证';
                        else if (data == 5) return '认证未通过';
                    }
                },
                {
                    "data": 'followMethod', "width": "19%", "bSortable": false, "sClass": "text-left",
                    "render": function (data, type, full, meta) {
                        var newData = data.replace('1', '电话').replace('2', '短信').replace('3', '邮件').replace('4', '平台即时通讯');
                        return newData;
                    }
                },
                {
                    "data": 'followRemark', "width": "19%",
                    "bSortable": false,
                    "sClass": "text-left position",
                    "render": function (data, type, full, meta) {
                        if (data == null) data = "";
                        return '<div class="text-hidden ellipsis" >' + data + '</div> ';
                    }
                }
            ],
            "columnDefs": [{
                "searchable": false,
                "orderable": false,
                "targets": 0,
            }
            ]
            ,
            "bProcessing": true,
            "ajax": {
                "url": '/EnterpriseUsers/GetEnterUsersFollowList',
                "type": 'POST',
                "data": { "enterNum": enterNum },
                "dataSrc": function (json) {
                    if (!json.data) {
                        json.data = [];
                    }
                    return json.data;
                }
            },
        });
    recordTable.on('order.dt search.dt', function () {
        recordTable.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
            cell.innerHTML = i + 1;
        });
    }).draw();


更多资料查阅网址:http://datatables.club/example/#data_sources

 

转载于:https://www.cnblogs.com/yeqrblog/p/8961367.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值