jQuery表格插件datatables用法總結(jié)
DataTables是一個(gè)jQuery的表格插件。這是一個(gè)高度靈活的工具,依據(jù)的基礎(chǔ)逐步增強(qiáng),這將增加先進(jìn)的互動(dòng)控制,支持任何HTML表格。
官方網(wǎng)站及其下載地址:http:/www.datatables.net
當(dāng)前最新版為1.10.2,讀者可點(diǎn)此本站下載。
其主要特點(diǎn)如下:
1.自動(dòng)分頁處理
2.即時(shí)表格數(shù)據(jù)過濾
3.數(shù)據(jù)排序以及數(shù)據(jù)類型自動(dòng)檢測
4.自動(dòng)處理列寬度
5.可通過CSS定制樣式
6.支持隱藏列
7.易用
8.可擴(kuò)展性和靈活性
9.國際化
10.動(dòng)態(tài)創(chuàng)建表格
11.免費(fèi)的
使用方法:
首先看看如下代碼:
<title>DataTables example</title> <style type="text/css" title="currentStyle"> @import "../../media/css/demo_page.css"; @import "../../media/css/demo_table.css"; @import "../examples_support/themes/smoothness/jquery-ui-1.7.2.custom.css"; </style> <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script> <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script> <script type="text/javascript" charset="utf-8">
上述代碼中引入js和css文件??梢栽赿emo里復(fù)制。注意路徑地址。
接著來看看如下代碼:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable( {
"oLanguage": {
"sUrl": "/SSS/dataTables/de_DE.txt"
},
"bStateSave": true,
//"bJQueryUI": true, //使用jqueryui 。我用的時(shí)候顯示的不是很好
"sPaginationType": "full_numbers"http://分頁
} );
} );
</script>
</head>
<body id="dt_example">//此處為body的id
<div id="container" align="center">//*div 里是 table ,table包括thead等,最好按此格式寫*
<h1>物品種類管理</h1>
<div id="demo">
<table cellpadding="5" cellspacing="0" border="1" class="display" id="example" align="center">//id 別忘了
<thead>
<tr>
<th>物品編號(hào)</th>
<th>物品名稱</th>
<th>物品單位</th>
<th>編輯狀態(tài)</th>
<th>隨便</th>
</tr>
</thead>
<tr class="gradeX">//此處可以是gradeA ,gradeX 等,但是gradeB 隔行換色 效果很好
<td>Trident</td>
<td>Internet
Explorer 4.0</td>
<td>Win 95+</td>
<td class="center">4</td>
<td class="center">X</td>
</tr>
<tr class="gradeC">
<td>Trident</td>
<td>Internet
Explorer 5.0</td>
<td>Win 95+</td>
<td class="center">5</td>
<td class="center">C</td>
</tr>
<tr class="gradeA">
<td>Trident</td>
<td>Internet
Explorer 5.5</td>
<td>Win 95+</td>
<td class="center">5.5</td>
<td class="center">A</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</div>
</div>
上面就能創(chuàng)建出如圖的效果, 分頁。排序。等等。
最后講講 各各屬性(主要添加的位置)
//$(document).ready(function() {
//$('#example').dataTable( {//加載
//"bPaginate": true,//分頁按鈕
//"bLengthChange": true,//每行顯示記錄數(shù)
//"bFilter": true,//搜索欄
//"bSort": true,//排序
//"bInfo": true,//Showing 1 to 10 of 23 entries 總記錄數(shù)沒也顯示多少等信息
//"bAutoWidth": true } );
//} );
//$(document).ready(function() {
//$('#example').dataTable( {
//"aaSorting": [[ 4, "desc" ]]//給列表排序 ,第一個(gè)參數(shù)表示數(shù)組 。4 就是css grade那列。第二個(gè)參數(shù)為 desc或是asc
//} );
//} );
//$(document).ready(function() {
//$('#example').dataTable( {
//"aoColumns": [
// /* Engine */ null, //默認(rèn)
// /* Browser */ null,
// /* Platform */ { "bSearchable": false, //不可參與搜索
// "bVisible": false },//不可見
// /* Version */ { "bVisible": false },//不可見
// /* Grade */ null
//] } );
//} );
//$(document).ready(function() {
//$('#example').dataTable({
//});
//} );
//$(document).ready(function() {
//$('#example').dataTable( {
//"sDom": '<"top"i>rt<"bottom"flp<"clear">'//這段是自定義布局沒搞明白挺復(fù)雜的。 * l - Length changing * f - Filtering input* t - The table!* i - Information* p - Pagination* r - pRocessing* < and > - div elements* <"class" and > - div with a class * Examples: <"wrapper"flipt>, <lf<t>ip>
//} );
//} );
//$(document).ready(function() {
// $('#example').dataTable( {
// "bStateSave": true //保存狀態(tài)到cookie *************** 很重要 , 當(dāng)搜索的時(shí)候頁面一刷新會(huì)導(dǎo)致搜索的消失。使用這個(gè)屬性就可避免了
//} );
//} );
//$(document).ready(function() {
//$('#example').dataTable( {
//"sPaginationType": "full_numbers" //分頁,一共兩種樣式 另一種為two_button 是datatables默認(rèn)
//} );
//} );
//$(document).ready(function() {
//$('#example').dataTable( { //分頁信息 不是很難理解。
//"oLanguage": {
//"sLengthMenu": "Display _MENU_ records per page",
//"sZeroRecords": "Nothing found - sorry",
//"sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
//"sInfoEmtpy": "Showing 0 to 0 of 0 records",
//"sInfoFiltered": "(filtered from _MAX_ total records)"
//}
//} );
//} )
$(document).ready(function() {
oTable = $('#example').dataTable({
"bJQueryUI": true, //可以添加 jqury的ui theme 需要添加css
"sPaginationType": "full_numbers"
});
} );
默認(rèn)的語言是英文的 當(dāng)然可以國際化:
"sUrl": "/SSS/dataTables/de_DE.txt" 添加個(gè)國際化的文件就可以。 名字隨便 路徑對(duì)了就可以。我寫的國際化文件內(nèi)容如下,可以直接復(fù)制到txt中使用.
{
"sProcessing": "Bitte warten...",
"sLengthMenu": "顯示_MENU_條 ",
"sZeroRecords": "沒有您要搜索的內(nèi)容",
"sInfo": "從_START_ 到 _END_ 條記錄——總記錄數(shù)為 _TOTAL_ 條",
"sInfoEmpty": "記錄數(shù)為0",
"sInfoFiltered": "(全部記錄數(shù) _MAX_ 條)",
"sInfoPostFix": "",
"sSearch": "搜索",
"sUrl": "",
"oPaginate": {
"sFirst": "第一頁",
"sPrevious": " 上一頁 ",
"sNext": " 下一頁 ",
"sLast": " 最后一頁 "
}
}
這些是datatables的基礎(chǔ)部分。比較容易掌握。
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)的學(xué)習(xí)有所幫助。
- JQuery動(dòng)態(tài)給table添加、刪除行 改進(jìn)版
- jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法
- jquery獲取table中的某行全部td的內(nèi)容方法
- jquery sortable的拖動(dòng)方法示例詳解
- jQuery操作表格(table)的常用方法、技巧匯總
- jquery easyui 結(jié)合jsp簡單展現(xiàn)table數(shù)據(jù)示例
- jQuery表格插件datatables用法詳解
- jQuery實(shí)現(xiàn)獲取table表格第一列值的方法
- jQuery實(shí)現(xiàn)動(dòng)態(tài)添加tr到table的方法
- jQuery實(shí)現(xiàn)動(dòng)態(tài)操作table行
相關(guān)文章
使用ajaxfileupload.js實(shí)現(xiàn)上傳文件功能
這篇文章主要為大家詳細(xì)介紹了使用ajaxfileupload.js實(shí)現(xiàn)上傳文件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
jQuery-1.9.1源碼分析系列(十)事件系統(tǒng)之事件包裝
這篇文章主要介紹了jQuery-1.9.1源碼分析系列(十)事件系統(tǒng)之事件包裝的相關(guān)資料,需要的朋友可以參考下2015-11-11
擴(kuò)展jQuery對(duì)象時(shí)如何擴(kuò)展成員變量具體怎么實(shí)現(xiàn)
這篇文章主要介紹了擴(kuò)展jQuery對(duì)象時(shí)如何擴(kuò)展成員變量,需要的朋友可以參考下2014-04-04
BootStrap table表格插件自適應(yīng)固定表頭(超好用)
這篇文章主要介紹了BootStrap table表格插件自適應(yīng)固定表頭(超好用)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
jquery+ajax實(shí)現(xiàn)跨域請求的方法
這篇文章主要介紹了jquery+ajax實(shí)現(xiàn)跨域請求的方法,詳細(xì)介紹了前臺(tái)及后臺(tái)的處理方法,是非常實(shí)用的技巧,需要的朋友可以參考下2015-01-01
分享8款優(yōu)秀的 jQuery 加載動(dòng)畫和進(jìn)度條插件
加載動(dòng)畫和進(jìn)度條在網(wǎng)站和 Web 應(yīng)用中的使用非常流行。雖然網(wǎng)速越來越快,但是我們的網(wǎng)站越來越復(fù)雜,同時(shí)用戶對(duì)網(wǎng)站的使用體驗(yàn)的要求也越來越高2012-10-10
jquery ajax傳遞中文參數(shù)亂碼問題及解決方法說明
本篇文章主要是對(duì)jquery ajax傳遞中文參數(shù)亂碼問題及解決方法進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02
jquery實(shí)現(xiàn)清新實(shí)用的網(wǎng)頁菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)清新實(shí)用的網(wǎng)頁菜單效果,涉及jquery通過鼠標(biāo)事件控制頁面元素的動(dòng)態(tài)隱藏與顯示實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
使用jquery的ajax需要注意的地方dataType的設(shè)置
沒有設(shè)置dataType:'json',就出現(xiàn)無法解析返回的data數(shù)據(jù),會(huì)把data當(dāng)作字符串處理,而不是json對(duì)象,記得以前是不用設(shè)dataType的,很奇怪,不知道是不是跟jquery版本有關(guān)系2013-08-08

