推荐是用ctrl+f查找使用,有写的不对的地方,也希望大家拍砖
更多datatables在http://dt.thxopen.com/ 欢迎大家来做客
fnCookieCallback:还没有使用过
- $(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;
- }
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnCreatedRow": function( nRow, aData, iDataIndex ) {
- // 为a的话字体加粗
- if ( aData[4] == "A" )
- {
- $('td:eq(4)', nRow).html( '<b>A</b>' );
- }
- }
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnDrawCallback": function( oSettings ) {
- alert( 'DataTables 重绘了' );
- }
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay ) {
- nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+iStart;
- }
- } );
- } )
- $(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;
- };
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnHeaderCallback": function( nHead, aData, iStart, iEnd, aiDisplay ) {
- nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
- }
- } );
- } )
- $('#example').dataTable( {
- "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
- return iStart +" to "+ iEnd;
- }
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnInitComplete": function(oSettings, json) {
- alert( 'DataTables 初始化完毕' );
- }
- } );
- } )
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnPreDrawCallback": function( oSettings ) {
- if ( $('#test').val() == 1 ) {
- return false;
- }
- }
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
- // 所有的a都加粗
- if ( aData[4] == "A" )
- {
- $('td:eq(4)', nRow).html( '<b>A</b>' );
- }
- }
- } );
- } );
- // 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
- } );
- }
- } );
- } );
- $(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" } );
- }
- } );
- } );
- $(document).ready( function() {
- $('#example').dataTable( {
- "bStateSave": true,
- "fnStateLoad": function (oSettings) {
- var o;
-
-
- //发送一个异步请求给服务器来返回数据
- //这是个同步的发送
- $.ajax( {
- "url": "/state_load",
- "async": false,
- "dataType": "json",
- "success": function (json) {
- o = json;
- }
- } );
-
- return o;
- }
- } );
- } );
- // 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;
- }
- } );
- } );
- // 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 );
- }
- } );
- } );
- $(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 () {}
- } );
- }
- } );
- } );
- // Remove a saved filter, so filtering is never saved
- $(document).ready( function() {
- $('#example').dataTable( {
- "bStateSave": true,
- "fnStateSaveParams": function (oSettings, oData) {
- oData.oSearch.sSearch = "";
- }
- } );
- } );