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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM