首页 技术 正文
技术 2022年11月15日
0 收藏 338 点赞 4,074 浏览 1048 个字

dataTable.NET是一個jQuery的plug in 第三方的library, 用來實現web page中table的interaction controls, 另外最近有在用的還有Telerik UI的RadGrid(action需要postback).

dataTable.NET可以通過簡單的setting,使已經define好的table columns調整顯示的順序或是隱藏,還可以對單個或多個columns進行sort.

在使用過程中有遇到一些有趣的狀況。

<table id="test-listing">
<thead>
<tr>
<th>column0</th>
<th>column1</th>
<th>column2</th>
<th>column3</th>
<th>column4</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
...
</tr>
...
</tbody>
</table>

以上面的table為例,當需要在顯示時對columns重新排序,並且隱藏某些columns時

$('#test-listing').DataTable({
paging: false,
ordering: true,
fixedHeader: true,
columnDefs: [3,1,4,2,0],
colReorder: {
order: [{"visible":false, "target":2}],
enable: false
},
"search": {
"search": "xxxx"
},
order: [[4, "asc"]],
"dom":
"<'row'f>" +
"<'row dt-table'" +
"<'sixteen wide column'tr>" +
">" +
"<'row'i>"
});

上面的setting,顯示在頁面上的結果

column3 column1 column4 column0
       

以column4升序排列。在setting中用到index為初始在頁面中定義的column的index。

當table已經load結束,可以使用下面的方法獲取當前的排序:

var table = $('#test-listing').dataTable();
var currentSort = table.fnSettings().aaSorting;

得到的sort會是以當前顯示的colums的index為準,[[2, “asc”]]

如果需要將抓到的當前sort存至cookie,下次頁面顯示時做為setting使用的話,記得先做轉換處理。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289