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