配置你想要的DataTables

$('#dataTable_ID1').dataTable({
    //"aaSorting" : [[1, "asc"]], //默認(rèn)的排序方式,第1+1列,升序排列
    "aLengthMenu" : [5, 10, 25, 50, 100], //更改顯示記錄數(shù)選項(xiàng)(默認(rèn):[10,25,50,100])
    "bAutoWidth" : false, // 禁用自適應(yīng)寬度(默認(rèn):true)
    //"bDeferRender":false,//推遲創(chuàng)建表元素每個(gè)元素,直到它們都創(chuàng)建完成(默認(rèn):false)
    "bDestroy" : true,//重新初始化表格,未匹配到表格則新建 (默認(rèn):false)
    "bFilter" : false,// 不適用搜索框過濾(默認(rèn):true)
    //"bInfo" : true, //顯示頁腳信息,左下角顯示記錄數(shù)(默認(rèn):true)
    //"bJQueryUI" : false, //不使用使用 jQury的UI theme(默認(rèn):false)
    "bLengthChange" : true,//顯示每頁幾條數(shù)據(jù)的顯示框(默認(rèn):true)
    //"bPaginate" : true, //顯示(應(yīng)用)分頁器,不開啟全顯示(默認(rèn):true)
    "bProcessing" : true,//加載進(jìn)度提示(默認(rèn):false)
    //"bScrollInfinite" : true, //啟動(dòng)初始化滾動(dòng)條(默認(rèn):false)
    //"bRetrieve":false,//使用指定的選擇器檢索表格,注意,如果表格已經(jīng)被初始化,該參數(shù)會(huì)直接返回已經(jīng)被創(chuàng)建的對(duì)象,并不會(huì)顧及你傳遞進(jìn)來的初始化參數(shù)對(duì)象的變化,將該參數(shù)設(shè)置為true說明你確認(rèn)已經(jīng)明白這一點(diǎn),如果你需要的話,bDestroy可以用來重新初始化表格(默認(rèn):false)
    "bServerSide" : true,//啟動(dòng)服務(wù)器端數(shù)據(jù)導(dǎo)入(默認(rèn):false)
    "bSort" : true,//啟用字段可排序(默認(rèn):true) TODO:單個(gè)列排序可禁用
    //"bStateSave" : true,//開啟狀態(tài)緩存,如分頁信息,展示長(zhǎng)度,開啟后在ajax刷新紀(jì)錄的時(shí)候不會(huì)將個(gè)性化設(shè)定重置為初始化狀態(tài),如: 會(huì)導(dǎo)致默認(rèn)的aaSorting設(shè)置失效(默認(rèn):false)
    //"bScrollCollapse" : true, //開啟高度自適應(yīng),當(dāng)數(shù)據(jù)條數(shù)不夠分頁數(shù)據(jù)條數(shù)的時(shí)候,插件高度隨數(shù)據(jù)條數(shù)而改變
    //"bScrollAutoCss":true,//指明滾動(dòng)的標(biāo)題元素是否被允許設(shè)置內(nèi)邊距和外邊距等(默認(rèn):true)
    //"bScrollCollapse":false,//當(dāng)垂直滾動(dòng)被允許的時(shí)候,不強(qiáng)制強(qiáng)制表格視圖在任何時(shí)候都是給定的高度(默認(rèn):false)
    //"bSortCellsTop":false,//允許使用底部的單元格,true為頂部(默認(rèn):false)
    //"iCookieDuration":7200,//cookie儲(chǔ)存時(shí)長(zhǎng)(單位:s)(默認(rèn):7200)
    //"iDeferLoading":null,//延時(shí)加載(type:int)(默認(rèn):null)
    //"iDisplayLength":10,//每頁顯示幾條數(shù)據(jù)(默認(rèn):10)
    //"iDisplayStart":0,//當(dāng)前頁開始的記錄序號(hào)(默認(rèn):0)
    //"iScrollLoadGap":100,//當(dāng)前頁面還有多少條數(shù)據(jù)可供滾動(dòng)時(shí)自動(dòng)加載新的數(shù)據(jù)(默認(rèn):100)
    "sDom": '<"top"l>rt<"bottom_left"i><"bottom_right"p><"clear">',//布局定義
        //格式指定:包括分頁,顯示多少條數(shù)據(jù)和搜索等
        //The following options are allowed:
        //    'l' - 左上角按個(gè)下拉框,10個(gè),20個(gè),50個(gè),所有的哪個(gè)
        //    'f' - 快速過濾框
        //    't' - 表格本身
        //    'i' - 分頁信息
        //    'p' - 分頁按鈕
        //    'r' - 現(xiàn)在正在加載中……
        //The following constants are allowed:
        //    'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')
        //    'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')
        //The following syntax is expected:
        //    '<' and '>' - div 元素
        //    '<"class" and '>' - 給div加clasa
        //    '<"#id" and '>' - 給div加上id
        //Examples:
        //    '<"wrapper"flipt>'
        //    '<lf<t>ip>'
        //例子:
        //'<"top"i>rt<"bottom"flp><"clear">'
        //解析結(jié)果:
        //    <div class="top">
        //    i
        //    </div>
        //    rt
        //    <div class="bottom">
        //    flp
        //    </div>
        //    <div class="clear"></div>
    "sPaginationType" : "full_numbers",//全頁數(shù)顯示 || "two_button":顯示兩個(gè)按鈕(默認(rèn):two_button)
    "sAjaxSource" : mediaHost+'/wxUsers/getDataTable1',
    //"sAjaxDataProp" : "aaDataName",//指定返回的數(shù)據(jù)對(duì)象名稱(默認(rèn):aaData)
    //"sScrollX" : 720, //DataTables的寬,可以是css設(shè)置,或者一個(gè)數(shù)字(單位:px),大于則開啟水平滾動(dòng)(默認(rèn):"blank string - i.e. disabled")
    //"sScrollY" : 480, //DataTables的高,可以是css設(shè)置,或者一個(gè)數(shù)字(單位:px),大于則開啟垂直滾動(dòng)(默認(rèn):"blank string - i.e. disabled")
    //"sCookiePrefix" : "SpryMedia_DataTables_",//指定cookie前綴(默認(rèn):"SpryMedia_DataTables_")


    //初始化過濾狀態(tài)
    //"oSearch":{
    //    "sSearch":"value",
    //    "bRegex":false, //value不當(dāng)成正則式
    //    "bSmart":true //靈活匹配策略
    //},

    //數(shù)據(jù)表列值
    "aoColumns" : [ {
        "mDataProp" : "data_properties0",
        "sClass" : "center",
        "bSortable" : false
        //"sDefaultContent":"",//此列默認(rèn)值為"",防數(shù)據(jù)無值報(bào)錯(cuò)
        //"bVisible" : false //不顯示此列
        }, {
            "mDataProp" : "data_properties1",
            "sClass" : "center",
            "bSortable" : false
        },  {
            "mDataProp" : "data_properties2",
            "sClass" : "center",
            "bSortable" : false
        }, {
            "mDataProp" : "data_properties2",
            "sClass" : "center",
            "bSortable" : false
        },
    ],

    //國際化配置
    "oLanguage" : {
        "sProcessing" : "正在加載數(shù)據(jù),請(qǐng)稍后...",
        "sLengthMenu" : "每頁顯示 _MENU_ 條記錄",
        "sZeroRecords" : "沒有數(shù)據(jù)!",
        "sEmptyTable" : "表中無數(shù)據(jù)存在!",
        "sInfo" : "當(dāng)前顯示 _START_ 到 _END_ 條,共 _TOTAL_ 條記錄",
        "sInfoEmpty" : "顯示0到0條記錄",
        "sInfoFiltered" : "數(shù)據(jù)表中共有 _MAX_ 條記錄",
        //"sInfoPostFix": "",
        //"sSearch": "搜索:",
        //"sUrl": "",
        //"sLoadingRecords": "載入中...",
        //"sInfoThousands": ",",
        "oPaginate" : {
            "sFirst" : "首頁",
            "sPrevious" : "上一頁",
            "sNext" : "下一頁",
            "sLast" : "末頁"
        }
        //"oAria": {
        //    "sSortAscending": ": 以升序排列此列",
        //    "sSortDescending": ": 以降序排列此列"
        //}
    },
    /**
     *
     * @param nRow 當(dāng)前行內(nèi)容
     * @param aaData 當(dāng)前數(shù)據(jù)對(duì)象
     * @param iDisplayIndex 當(dāng)前行索引,從0開始
     * @param iDisplayIndexOfAadata 當(dāng)前對(duì)象所在對(duì)象數(shù)組的索引,從0開始
     * @returns {*}
     */
    "fnRowCallback" : function(nRow, aaData, iDisplayIndex, iDisplayIndexOfAadata) {

        //修改第一列為多選框內(nèi)容
        var firstTDHtml = '<label>firstTDHtml</label>';
        $('td:eq(0)', nRow).html(firstTDHtml);

        //修改第二列為序號(hào)
        var secondTDHtml = iDisplayIndex+1;
        $('td:eq(1)', nRow).html(secondTDHtml);

        return nRow;
    },
    "fnDrawCallback" : function(oSettings) {
        // jAlert( 'DataTables 重繪了' );
    },
    "fnFooterCallback" : function(nFoot, aData, iStart, iEnd, aiDisplay) {
        // jAlert("FooterCallback");
    },
});
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容