fnCookieCallback:尚未使用過php
$(document).ready(function () { $('#example').dataTable({ "fnCookieCallback": function (sName, oData, sExpires, sPath) { // Customise oData or sName or whatever else here return sName + "=" + JSON.stringify(oData) + "; expires=" + sExpires + "; path=" + sPath; } }); });
fnCreatedRow:顧名思義,建立行得時候的回調函數html
$(document).ready(function () { $('#example').dataTable({ "fnCreatedRow": function (nRow, aData, iDataIndex) { // 爲a的話字體加粗 if (aData[4] == "A") { $('td:eq(4)', nRow).html('<b>A</b>'); } } }); });
fnDrawCallback:draw畫 ,這個應該是重繪的回調函數ajax
$(document).ready(function () { $('#example').dataTable({ "fnDrawCallback": function (oSettings) { alert('DataTables 重繪了'); } }); });
fnFooterCallback:底部的回調函數,這個能夠用來作總計之類的功能json
$(document).ready(function() { $('#example').dataTable({ "fnFooterCallback": function(nFoot, aData, iStart, iEnd, aiDisplay) { nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is " + iStart; } }); });
fnFormatNumber:顧名思義,格式化數字的顯示方式服務器
$(document).ready(function () { $('#example').dataTable({ "fnFormatNumber": function (iIn) { if (iIn < 1000) { return iIn; } else { var s = (iIn + ""), a = s.split(""), out = "", iLen = s.length; for (var i = 0; i < iLen; i++) { if (i % 3 === 0 && i !== 0) { out = "'" + out; } out = a[iLen - i - 1] + out; } } return out; } }); });
fnHeaderCallback:表頭的回調函數async
$(document).ready(function () { $('#example').dataTable({ "fnHeaderCallback": function (nHead, aData, iStart, iEnd, aiDisplay) { nHead.getElementsByTagName('th')[0].innerHTML = "Displaying " + (iEnd - iStart) + " records"; } }); })
fnInfoCallback:datatables信息的回調函數ide
$('#example').dataTable({ "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) { return iStart + " to " + iEnd; } });
fnInitComplete:datatables初始化完畢後會調用這個方法函數
$(document).ready(function () { $('#example').dataTable({ "fnInitComplete": function (oSettings, json) { alert('DataTables has finished its initialisation.'); } }); });
fnPreDrawCallback:每一次繪datatables時候調用的方法
字體
$(document).ready(function () { $('#example').dataTable({ "fnPreDrawCallback": function (oSettings) { if ($('#test').val() == 1) { return false; } } }); });
fnRowCallback:行的回調函數this
$(document).ready(function () { $('#example').dataTable({ "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) { // Bold the grade for all 'A' grade browsers if (aData[4] == "A") { $('td:eq(4)', nRow).html('<b>A</b>'); } } }); });
fnServerData:這個是結合服務器模式的回調函數,用來處理服務器返回過來的數據
// POST data to server $(document).ready(function () { $('#example').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "xhr.php", "fnServerData": function (sSource, aoData, fnCallback, oSettings) { oSettings.jqXHR = $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback }); } }); });
fnServerParams:向服務器傳額外的參數
$(document).ready(function () { $('#example').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "scripts/server_processing.php", "fnServerParams": function (aoData) { aoData.push({ "name": "more_data", "value": "my_value" }); } }); });
fnStateLoad:讀取狀態的回調函數
$(document).ready(function () { $('#example').dataTable({ "bStateSave": true, "fnStateLoad": function (oSettings) { var o; // Send an Ajax request to the server to get the data. Note that // this is a synchronous request. $.ajax({ "url": "/state_load", "async": false, "dataType": "json", "success": function (json) { o = json; } }); return o; } }); });
fnStateLoadParams:和上面的不知道什麼區別,沒用過
// Remove a saved filter, so filtering is never loaded $(document).ready(function () { $('#example').dataTable({ "bStateSave": true, "fnStateLoadParams": function (oSettings, oData) { oData.oSearch.sSearch = ""; } }); }); // Disallow state loading by returning false $(document).ready(function () { $('#example').dataTable({ "bStateSave": true, "fnStateLoadParams": function (oSettings, oData) { return false; } }); });
fnStateLoaded:又是這個,加了ed 不知道意思沒用過
// Show an alert with the filtering value that was saved $(document).ready(function () { $('#example').dataTable({ "bStateSave": true, "fnStateLoaded": function (oSettings, oData) { alert('Saved filter was: ' + oData.oSearch.sSearch); } }); });
fnStateSave:狀態儲存
$(document).ready( function() { $('#example').dataTable({ "bStateSave": true, "fnStateSave": function(oSettings, oData) { // Send an Ajax request to the server with the state object $.ajax({ "url": "/state_save", "data": oData, "dataType": "json", "method": "POST" "success": function () { } }); }; } ); } );
fnStateSaveParams :狀態儲存參數,沒用過,不明白
// Remove a saved filter, so filtering is never saved $(document).ready(function () { $('#example').dataTable({ "bStateSave": true, "fnStateSaveParams": function (oSettings, oData) { oData.oSearch.sSearch = ""; } }); });