Jquery_JQuery之DataTables強大的表格解決方案

1、DataTables的默認配置

$(document).ready(function() {
$(‘#example’).dataTable();
} );

示例:http://www.guoxk.com/html/DataTables/Zero-configuration.html

2、DataTables的一些基礎屬性配置

復制代碼
“bPaginate”: true, //翻頁功能
“bLengthChange”: true, //改變每頁顯示數據數量
“bFilter”: true, //過濾功能
“bSort”: false, //排序功能
“bInfo”: true,//頁腳信息
“bAutoWidth”: true//自動寬度
復制代碼

示例:http://www.guoxk.com/html/DataTables/Feature-enablement.html

3、數據排序

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“aaSorting”: [
[ 4, "desc" ]
]
} );
} );
從第0列開始,以第4列倒序排列
復制代碼

示例:http://www.guoxk.com/html/DataTables/Sorting-data.html

4、多列排序

示例:http://www.guoxk.com/html/DataTables/Multi-column-sorting.html

?

5、隱藏某些列

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“aoColumnDefs”: [
{ "bSearchable": false, "bVisible": false, "aTargets": [ 2 ] },
{ “bVisible”: false, “aTargets”: [ 3 ] }
] } );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/Hidden-columns.html

6、改變頁面上元素的位置

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“sDom”: ‘<”top”fli>rt<”bottom”p><”clear”>’
} );
} );
//l- 每頁顯示數量
//f – 過濾輸入
//t – 表單Table
//i – 信息
//p – 翻頁
//r – pRocessing
//< and > – div elements
//<”class” and > – div with a class
//Examples: <”wrapper”flipt>, <lf<t>ip>
復制代碼

示例:http://www.guoxk.com/html/DataTables/DOM-positioning.html

7、狀態保存,使用了翻頁或者改變了每頁顯示數據數量,會保存在cookie中,下回訪問時會顯示上一次關閉頁面時的內容。

$(document).ready(function() {
$(‘#example’).dataTable( {
“bStateSave”: true
} );
} );

示例:http://www.guoxk.com/html/DataTables/State-saving.html

8、顯示數字的翻頁樣式

$(document).ready(function() {
$(‘#example’).dataTable( {
“sPaginationType”: “full_numbers”
} );
} );

示例:http://www.guoxk.com/html/DataTables/Alternative-pagination-styles.html

9、水平限制寬度

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“sScrollX”: “100%”,
“sScrollXInner”: “110%”,
“bScrollCollapse”: true
} );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/Horizontal.html

10、垂直限制高度

示例:http://www.guoxk.com/html/DataTables/Vertical.html

11、水平和垂直兩個方向共同限制

示例:http://www.guoxk.com/html/DataTables/HorizontalVerticalBoth.html

12、改變語言

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“oLanguage”: {
“sLengthMenu”: “每頁顯示 _MENU_ 條記錄”,
“sZeroRecords”: “抱歉, 沒有找到”,
“sInfo”: “從 _START_ 到 _END_ /共 _TOTAL_ 條數據”,
“sInfoEmpty”: “沒有數據”,
“sInfoFiltered”: “(從 _MAX_ 條數據中檢索)”,
“oPaginate”: {
“sFirst”: “首頁”,
“sPrevious”: “前一頁”,
“sNext”: “后一頁”,
“sLast”: “尾頁”
},
“sZeroRecords”: “沒有檢索到數據”,
“sProcessing”: “<img src=\'#\'" /loading.gif’ />”
}
} );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/Change-language-information.html

13、click事件

示例:http://www.guoxk.com/html/DataTables/event-click.html

14/配合使用tooltip插件

示例:http://www.guoxk.com/html/DataTables/tooltip.html

15、定義每頁顯示數據數量

$(document).ready(function() {
$(‘#example’).dataTable( {
“aLengthMenu”: [[10, 25, 50, -1], [10, 25, 50, "All"]]
} );
} );

示例:http://www.guoxk.com/html/DataTables/length_menu.html

16、row callback

示例:http://www.guoxk.com/html/DataTables/RowCallback.html

最后一列的值如果為“A”則加粗顯示

17、排序控制

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“aoColumns”: [
null,
{ "asSorting": [ "asc" ] },
{ “asSorting”: [ "desc", "asc", "asc" ] },
{ “asSorting”: [ ] },
{ “asSorting”: [ ] }
]
} );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/sort.html
說明:第一列點擊按默認情況排序,第二列點擊已順序排列,第三列點擊一次倒序,二三次順序,第四五列點擊不實現排序

18、從配置文件中讀取語言包

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“oLanguage”: {
“sUrl”: “cn.txt”
}
} );
} );
復制代碼

19、是用ajax源

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“bProcessing”: true,
“sAjaxSource”: ‘./arrays.txt’
} );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/ajax.html

20、使用ajax,在服務器端整理數據

復制代碼
$(document).ready(function() {
$(‘#example’).dataTable( {
“bProcessing”: true,
“bServerSide”: true,
“sPaginationType”: “full_numbers”,
“sAjaxSource”: “./server_processing.php”,
/*如果加上下面這段內容,則使用post方式傳遞數據
“fnServerData”: function ( sSource, aoData, fnCallback ) {
$.ajax( {
“dataType”: ‘json’,
“type”: “POST”,
“url”: sSource,
“data”: aoData,
“success”: fnCallback
} );
}*/
“oLanguage”: {
“sUrl”: “cn.txt”
},
“aoColumns”: [
{ "sName": "platform" },
{ "sName": "version" },
{ "sName": "engine" },
{ "sName": "browser" },
{ "sName": "grade" }
]//$_GET['sColumns']將接收到aoColumns傳遞數據
} );
} );
復制代碼

示例:http://www.guoxk.com/html/DataTables/ajax-serverSide.html

21、為每行加載id和class

復制代碼
服務器端返回數據的格式:
{
“DT_RowId”: “row_8″,
“DT_RowClass”: “gradeA”,
“0″: “Gecko”,
“1″: “Firefox 1.5″,
“2″: “Win 98+ / OSX.2+”,
“3″: “1.8″,
“4″: “A”
},
復制代碼

示例:http://www.guoxk.com/html/DataTables/add_id_class.html

22、為每行顯示細節,點擊行開頭的“+”號展開細節顯示

示例:http://www.guoxk.com/html/DataTables/with-row-information.html

?

23、選擇多行

示例:http://www.guoxk.com/html/DataTables/selectRows.html

22、集成jQuery插件jEditable

示例:http://www.guoxk.com/html/DataTables/jEditable-integration.html

?更過參考:

要注意的是,要被dataTable處理的table對象,必須有thead與tbody,而且,結構要規整(數據不一定要完整),這樣才能正確處理。

以下是在進行dataTable綁定處理時候可以附加的參數:

屬性名稱取值范圍解釋
bAutoWidthtrue or false, default true是否自動計算表格各列寬度
bDeferRendertrue or false, default false用于渲染的一個參數
bFiltertrue or false, default true開關,是否啟用客戶端過濾功能
bInfotrue or false, default true開關,是否顯示表格的一些信息
bJQueryUItrue or false, default false是否使用jquery ui themeroller的風格
bLengthChangetrue or false, default true開關,是否顯示一個每頁長度的選擇條(需要分頁器支持)
bPaginatetrue or false, default true開關,是否顯示(使用)分頁器
bProcessingtrue or false, defualt false開關,以指定當正在處理數據的時候,是否顯示“正在處理”這個提示信息
bScrollInfinitetrue or false, default false開關,以指定是否無限滾動(與sScrollY配合使用),在大數據量的時候很有用。當這個標志為true的時候,分頁器就默認關閉
bSorttrue or false, default true開關,是否讓各列具有按列排序功能
bSortClassestrue or false, default true開關,指定當當前列在排序時,是否增加classes 'sorting_1', 'sorting_2' and 'sorting_3',打開后,在處理大數據時,性能有所損失
bStateSavetrue or false, default false開關,是否打開客戶端狀態記錄功能。這個數據是記錄在cookies中的,打開了這個記錄后,即使刷新一次頁面,或重新打開瀏覽器,之前的狀態都是保存下來的
sScrollX'disabled' or? '100%' 類似的字符串是否開啟水平滾動,以及指定滾動區域大小
sScrollY'disabled' or '200px' 類似的字符串是否開啟垂直滾動,以及指定滾動區域大小
------
選項??
aaSortingarray array[int,string], 如[], [[0,'asc'], [0,'desc']]指定按多列數據排序的依據
aaSortingFixed同上同上。唯一不同點是不能被用戶的自定義配置沖突
aLengthMenudefault [10, 25, 50, 100],可以為一維數組,也可為二維數組,比如:[[10, 25, 50, -1], [10, 25, 50, "All"]]這個為選擇每頁的條目數,當使用一個二維數組時,二維層面只能有兩個元素,第一個為顯示每頁條目數的選項,第二個是關于這些選項的解釋
aoSearchColsdefault null, 類似:[null, {"sSearch": "My filter"}, null,{"sSearch": "^[0-9]", "bEscapeRegex": false}]給每個列單獨定義其初始化搜索列表特性(這一塊還沒搞懂)
asStripClassesdefault ['odd', 'even'], 比如['strip1', 'strip2', 'strip3']指定要被應用到各行的class風格,會自動循環
bDestroytrue or false, default false用于當要在同一個元素上執行新的dataTable綁定時,將之前的那個數據對象清除掉,換以新的對象設置
bRetrievetrue or false, default false用于指明當執行dataTable綁定時,是否返回DataTable對象
bScrollCollapsetrue or false, default false指定適當的時候縮起滾動視圖
bSortCellsToptrue or false, default false(未知的東東)
iCookieDuration整數,默認7200,單位為秒指定用于存儲客戶端信息到cookie中的時間長度,超過這個時間后,自動過期
iDeferLoading整數,默認為null延遲加載,它的參數為要加載條目的數目,通常與bServerSide,sAjaxSource等配合使用
iDisplayLength整數,默認為10用于指定一屏顯示的條數,需開啟分頁器
iDisplayStart整數,默認為0用于指定從哪一條數據開始顯示到表格中去
iScrollLoadGap整數,默認為100用于指定當DataTable設置為滾動時,最多可以一屏顯示多少條數據
oSearch默認{ "sSearch": "", "bRegex": false, "bSmart": true }又是初始時指定搜索參數相關的,有點復雜,沒搞懂目前
sAjaxDataProp字符串,default 'aaData'指定當從服務端獲取表格數據時,數據項使用的名字
sAjaxSourceURL字符串,default null指定要從哪個URL獲取數據
sCookiePrefix字符串,default 'SpryMedia_DataTables_'當打開狀態存儲特性后,用于指定存儲在cookies中的字符串的前綴名字
sDomdefault lfrtip (when bJQueryUI is false) or <"H"lfr>t<"F"ip> (when bJQueryUI is true)這是用于定義DataTable布局的一個強大的屬性,另開專門文檔來補充說明吧
sPaginationType'full_numbers' or 'two_button', default 'two_button'用于指定分頁器風格
sScrollXInnerstring default 'disabled'又是水平滾動相關的,沒搞懂啥意思

DataTable支持如下回調函數?

回調函數名稱參數返回值默認功能
fnCookieCallback1.string: Name of the cookie defined by DataTables 2.object: Data to be stored in the cookie 3.string: Cookie expires string 4.string: Path of the cookie to setstring: cookie formatted string (which should be encoded by using encodeURIComponent())null當每次cookies改變時,會觸發這個函數調用
fnDrawCallback在每次table被draw完后調用,至于做什么就看著辦吧
fnFooterCallback1.node : "TR" element for the footer 2.array array strings : Full table data (as derived from the original HTML) 3.int : Index for the current display starting point in the display array< 4.int : Index for the current display ending point in the display array 5.array int : Index array to translate the visual position to the full data array用于在每次重畫的時候修改表格的腳部
fnFormatNumber1.int : number to be formattedString : formatted string for DataTables to show the number有默認的用于在大數字上,自動加入一些逗號,分隔開
fnHeaderCallback1.node : "TR" element for the header 2.array array strings : Full table data (as derived from the original HTML) 3.int : Index for the current display starting point in the display array 4.int : Index for the current display ending point in the display array 5.array int : Index array to translate the visual position to the full data array用于在每次draw發生時,修改table的header
fnInfoCallback1.object: DataTables settings object 2.int: Starting position in data for the draw 3.int: End position in data for the draw 4.int: Total number of rows in the table (regardless of filtering) 5.int: Total number of rows in the data set, after filtering 6.string: The string that DataTables has formatted using it's own rulesstring: The string to be displayed in the information element.用于傳達table信息
fnInitComplete1.object:oSettings - DataTables settings object表格初始化完成后調用
fnPreDrawCallback1.object:oSettings - DataTables settings objectBoolean用于在開始繪制之前調用,返回false的話,會阻止draw事件發生;返回其它值,draw可以順利執行
fnRowCallback1.node : "TR" element for the current row 2.array strings : Raw data array for this row (as derived from the original HTML) 3.int : The display index for the current table draw 4.int : The index of the data in the full list of rows (after filtering)node : "TR" element for the current row當創建了行,但還未繪制到屏幕上的時候調用,通常用于改變行的class風格
fnServerData1.string: HTTP source to obtain the data from (i.e. sAjaxSource) 2.array objects: A key/value pair object containing the data to send to the server 3.function: Function to be called on completion of the data get process that will draw the data on the page.void$.getJSON用于替換默認發到服務端的請求操作
fnStateLoadCallback1.object:oSettings - DataTables settings object 2.object:oData - Object containing information retrieved from the state saving cookie which should be restored. For the exact properties please refer to the DataTables code.Boolean - false if the state should not be loaded, true otherwise在cookies中的數據被加載前執行,可以方便地修改這些數據
fnStateSaveCallback1.object:oSettings - DataTables settings object 2.String:sValue - a JSON string (without the final closing brace) which should be stored in the state saving cookie.String - the full string that should be used to save the state在狀態數據被存儲到cookies前執行,可以方便地做一些預操作

?

注:

手動刷新數據時,數據累加不重新加載問題解決辦法:

var oTableTemp=$('#'+tableId).dataTable({"bDestroy":true});
oTableTemp.fnClearTable();
oTableTemp=$('#'+tableId).dataTable({"bDestroy":true});

?

?

轉自:http://www.cnblogs.com/jobs2/p/3431567.html

文檔:http://legacy.datatables.net/usage/options

轉載于:https://www.cnblogs.com/gisblogs/p/4863101.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/256612.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/256612.shtml
英文地址,請注明出處:http://en.pswp.cn/news/256612.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

內存管理1retain和release

Student.h: #import <Foundation/Foundation.h> interface Student : NSObject property int age; //默認會生成一個_age屬性 end Student.m: #import "Student.h" implementation Student //synthesize age_age;//xcode4.5中可以不使用synthesise方法&a…

目標檢測的圖像特征提取之(一)Hog特征提取

Hog特征實質是&#xff1a;梯度的統計信息,即針對邊緣作特征提取 意義&#xff1a;目標的表象和形狀 轉載于zouxy09大神的文章&#xff0c;加上自己些微的理解和應用&#xff01; http://blog.csdn.net/zouxy09/article/details/7929348/ 上述基本講清楚了&#xff0c;其實…

redis類型[string 、list 、 set 、sorted set 、hash]

1. Keys redis本質上一個key-value db&#xff0c;所以我們首先來看看他的key. 首先key也是字符串類型&#xff0c;但是key中不能包括邊界字符&#xff1b;由于key不是binary safe的字符串&#xff0c;所以像"my key"和"mykey\n"這樣包含空格和換行的key是…

matlab simulink筆記02——延遲模塊delay與單位延遲模塊unit delay

延遲模塊 單位延遲模塊 延遲模塊具有復位功能,當滿足復位條件時會進行復位操作,即輸出的值會恢復到初始值,而單位延遲模塊沒有復位功能; 延遲模塊的步長是可以設置的,而單位延遲模塊的步長固定為1,不可以改變

局域網傳輸速度升級

現在很多單位都建成了企業內部局域網&#xff0c;一般的企業網絡大多是使用雙 絞線連接網卡的方式來進行通信的。其中雙絞線通常采用的都是5類線&#xff0c;傳輸速率為100MB。而網卡則有一定的區別&#xff0c;很多網卡都是采取 10Mbps/100Mbmps自適應的網卡&#xff0c;即傳輸…

數據結構--棧 codevs 1107 等價表達式

codevs 1107 等價表達式 2005年NOIP全國聯賽提高組 時間限制: 1 s空間限制: 128000 KB題目等級 : 鉆石 Diamond題目描述 Description明明進了中學之后&#xff0c;學到了代數表達式。有一天&#xff0c;他碰到一個很麻煩的選擇題。這個題目的題干中首先給出了一個代數表達式&am…

目標檢測的圖像特征提取之(二)LBP特征

LBP特征實質是&#xff1a;圖像局部特征的提取 意義&#xff1a;紋理的提取 http://blog.csdn.net/zouxy09/article/details/7929531 1&#xff09;首先將檢測窗口劃分為1616的小區域&#xff08;cell&#xff09;&#xff1b; &#xff08;2&#xff09;對于每個cell中的一個…

VS2010安裝幫助文檔出現錯誤

安裝VS2010后的幫助文檔安裝出現錯誤:未能在指定文件夾中創建本地存儲區 安裝完VS2010后&#xff0c;出現錯誤&#xff0c;取消后 再安裝MSDN 打開“Help Library 管理器 - Microsoft Help 查看器 1.0” 提示“請為本地內容選擇位置” 默認的位置是在“C:\Documents and Settin…

matlab smulink筆記03——過零檢測

★過零檢測 變步長解算方法動態地評估計算下一個采樣時刻所使用的步長&#xff0c;當前后兩個采 樣點的狀態值變化大時&#xff0c;則縮小采樣步長&#xff0c;當前后兩個采樣點的值變化小時則增大步 這種做法使得解算器在計算不連續臨近區域時使用較小的步長&#xff0c;因為不…

電腦下鄉的遐想

最近討論家電下鄉的話題很熱&#xff0c;其中我個人最關心“電腦下鄉”。原因是&#xff0c;我是農村人&#xff0c;正好在電腦相關行業里混。 應當說&#xff0c;讓電腦下鄉是我多年的夢想&#xff0c;我多么盼望鄉下的鄉親們能夠上網看新聞、學習、看電視……但是&#xff0c…

angularjs學習曲線

angularjs學習曲線 剛開始學Augular覺得開發應用需要有相當的編程基礎. 不得不說這確實是一款了不起的開發框架&#xff0c;它要求開發人員設計低耦合和可維護的應用. 使用AngularJS 的復雜度就像使用PHP&#xff0c;Ruby on Rails等等, 都需要處理依賴注入&#xff0c;路由&am…

HttpWebRequest post上傳文件

public static string HttpUploadFile(string url, string path){// 設置參數 HttpWebRequest request WebRequest.Create(url) as HttpWebRequest;CookieContainer cookieContainer new CookieContainer();request.CookieContainer cookieContainer;request.AllowAutoRedir…

文章標題

**1>MSVCRTD.lib(exe_main.obj) : error LNK2019: 無法解析的外部符號 main&#xff0c;該符號在函數 “int __cdecl invoke_main(void)” (?invoke_mainYAHXZ) 中被引用 1>D:\vs2015-code\Imae_Client\x64\Debug\Imae_Client.exe : fatal error LNK1120: 1 個無法解析…

matlab simulink筆記04——switch模塊

Switch 模塊 Switch模塊是-.個選擇開關模塊,可根據判斷條件選擇多個輸入端口中的某個進行輸出。圖所示為CommonlyUsedBlocks中具有3個輸入端口.1個輸出端口的Switch模塊圖標。模塊的3個端口中,第1個和第3個端口為輸出端口提供輸出值,輸出端口輸出第1個輸人口還是第3個輸人口的值…

[Ajax]ajax學習與理解

1.新建demo.aspx頁面。2.首先在該頁面的后臺文件demos.aspx.cs中添加引用。 using System.Web.Services;3.無參數的方法調用. 大家注意了&#xff0c;這個版本不能低于.net framework 2.0。2.0已下不支持的。后臺代碼&#xff1a; [WebMethod] public static string SayHel…

優化Web網站性能

一、前端優化網站性能優化是一個很綜合的話題&#xff0c;涉及到服務器的配置和網站前后端程序等各個方面&#xff0c;我只是從實際經歷出發&#xff0c;分享一下自己所嘗試過的網站性能優化方法。之所以在標題上掛一個web2.0&#xff0c;是因為本文更偏重于中小網站的性能優化…

Gym - 100851F Froggy Ford kruskal

題目鏈接&#xff1a; http://acm.hust.edu.cn/vjudge/problem/307216Froggy FordTime Limit: 3000MS題意 青蛙過河&#xff0c;河中有若干個石頭&#xff0c;現在你可以加一個石頭&#xff0c;使得青蛙從左岸跳到右岸的最大跳躍距離最小。 題解 把左岸和右岸作為兩個虛節點&am…

Tesseract入門-VS2015下調用Tesseract4.0 +win7 64位系統

本文是基于最近的OCR識別項目學習ocr開源庫-tesseract的簡單調用&#xff0c;不涉及其余視覺知識。 參考文獻&#xff1a;http://blog.csdn.net/u012566751/article/details/54136836 參考庫&#xff1a;http://download.csdn.net/download/u010554381/10044876 1.預備工作 …

authconfig命令解析_學習筆記

時間&#xff1a;2017.11.16作者&#xff1a;李強參考&#xff1a;man,info&#xff0c;magedu講義聲明&#xff1a;以下英文純屬個人翻譯&#xff0c;英文B級&#xff0c;歡迎糾正&#xff0c;盜版不糾,才能有限&#xff0c;希望不誤人子弟為好。1、使用目的與場景先列在這里&…