JQuery Datatables Columns API 参数详细说明
---恢复内容开始---
Data Tables: http://datatables.NET/
Version: 1.10.0
Columns说明
虽然我们可以通过DOM直接获取DataTables元素的信息,但是DataTables提供了更方便的方法,可以自定义列的属性。下边就让我们一起来学习DataTables是怎么来定义列属性的。
- DataTables提供了两个参数来定义列属性:columns 和 columnDefs (源代码里:aoColumns 和 aoColumnDefs)
- 为了用户定义的参数更易于理解,DataTables提供的用户参数名和源代码的参数名是不一样的,不过这两个参数名,不管使用哪个,最终效果是一样的。(*以下参数说明都是用户使用参数名)
columns 和 columnDefs的区别:
- 相同点:达到相同的效果
- 不同点:作用不一样,使用不一样(需要一个目标属性在每个定义的对象(columnDefs.targetsDT))
- columns:设置特定列的初始化属性,可以定义数组设置多列,数组长度必须等于表格的数量,只想使用默认值可以设为“NULL”,数组每个元素只能设置单列的属性。
- columnDefs:与columns非常相似,该数组可以针对特定的列,多列或者所有列定义。数组可以任意长度。通过targets参数设置一个列或者多列,该属性定义可以如下:
- 0或正整数 - 从左边的列索引计数
- 负整数 - 列索引从右边计数
- 一个字符串 - 类名称将被匹配上的TH为列
- 字符串“_all” - 所有的列(即指定一个默认值)
- 两个参数可以同时使用,但是columns定义的优先级最高。
- 当columnDefs里对同一列有多个定义时,最开始的定义优先级最高。
example:
- $('#example').dataTable(
- {
- data: [
- {
- "name": "Tiger Nixon1",
- "position": "System Architect1",
- "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
- "salary": "$3,1201",
- "start_date": "2011/04/25",
- "office": "Edinburgh1",
- "extn": "54211"
- },
- {
- "name": "Tiger Nixon2",
- "position": "System Architect2",
- "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
- "salary": "$3,1202",
- "start_date": "2011/04/25",
- "office": "Edinburgh2",
- "extn": "54212"
- },
- {
- "name": "Tiger Nixon3",
- "position": "System Architect3",
- "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
- "salary": "$3,1203",
- "start_date": "2011/04/25",
- "office": "Edinburgh3",
- "extn": "54213"
- }
- ],
- columnDefs: [
- {
- "targets": 0,
- "searchable": false
- },
- {
- "targets": [1,2,3],
- "orderData": [ 2, 3, 4 ],
- "searchable": false
- },
- {
- "targets": [-3,-4],
- "orderable": false,
- "searchable": false
- }
- ],
- columns: [
- { "name": "name",
- "cellType": "th",
- "orderDataType": "dom-text",
- "orderSequence": [ "desc","asc", "asc" ],
- "className": "my_class",
- "contentPadding": "mmm",
- "createdCell": function (td, cellData, rowData, row, col) {
- if ( row < 1 ) {
- $(td).css('color', 'red');
- }
- },
- "data": "name",
- "searchable": true,
- "title": "My Name"
- },
- {
- "data": "position",
- "render": function ( data, type, full, meta ) {
- return '<a href="'+data+'">' + data + '</a>';
- }
- },
- {
- "data": 'phone',
- "render": {
- "_": "plain",
- "filter": "filter",
- "display": "display"
- }
- },
- { "data": "office" },
- { "data": "start_date", "type": "date" },
- { "data": "extn", "visible": false},
- { "data": "salary", "width": "20px" },
- {
- "data": null,
- "orderable": false,
- "defaultContent": "<button>Edit</button>"
- }
- ]
- }
- );
| 用户参数名 | 源码参数名 | 英文解释 | 中文解释 |
|
cellType |
sCellType |
Cell type to be created for a column | 设置列标签的类型(ex:th,td) |
| className |
sClass |
Class to assign to each cell in the column | 设置列的class属性值 |
| contentPadding |
sContentPadding |
Add padding to the text content used when calculating the optimal with for a table. | 设置填充内容,以计算与优化为一个表时所使用的文本内容,一般不需要设置 |
| createdCell |
fnCreatedCell |
Cell created callback to allow DOM manipulation | 设置cell创建完后的回调函数,设置背景色或者添加行 |
| data |
mData |
Set the data source for the column from the rows data object / array | 设置单元格里的值 |
| defaultContent |
sDefaultContent |
Set default, static, content for a column | 设置列的默认值 |
| name |
sName |
Set a descriptive name for a column | 设置列的描述性名称 |
| orderable |
bSortable |
Enable or disable ordering on this column | 设置列是否可以排序 |
| orderData |
aDataSort |
Define multiple column ordering as the default order for a column | 设置多列排序时列的默认顺序 |
| orderDataType | sSortDataType | Live DOM sorting type assignment | |
| orderSequence |
asSorting |
Order direction application sequence | 设置列的默认排序,可以改变列排序的顺序处理 |
| render |
mRender |
Render (process) the data for use in the table | |
| searchable |
bSearchable |
Enable or disable filtering on the data in this column | 设置列的数据是否过滤 |
| title | sTitle | Set the column title | 设置列的标题 |
| type | sType |
Set the column type - used for filtering and sorting string processing. Four types (string, numeric, date and html (which will strip HTML tags before ordering)) are currently available. |
设置列的类型,用于过滤和排序的字符串处理。 |
| visible | bVisible | Enable or disable the display of this column | 设置列是否显示 |
| width | sWidth | Column width assignment | 定义列的宽度 |
参考资料:http://datatables.Net/reference/option/
---恢复内容结束---
JQuery Datatables Columns API 参数详细说明的更多相关文章
- JQuery中的AJAX参数详细介绍
Jquery中AJAX参数详细介绍 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方 ...
- JQuery插件datatables相关api
学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...
- jquery datatables api (转)
学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...
- 最全的jquery datatables api 使用详解
学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...
- jquery datatables api
原文地址 学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/ ...
- Jquery Datatables 请求参数及接收参数处理
Jquery Datatables 请求参数及接收参数处理 /** * Created by wb-wuyifu on 2016/8/9. */ /** * Created by wb-wuyifu ...
- 转载 Jquery中AJAX参数详细介绍
Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ...
- Jquery中AJAX参数详细(1)-转
http://www.cnblogs.com/qiufuwu618/archive/2012/12/20/2826190.html Jquery中AJAX参数详细列表: 参数名 类型 描述 url S ...
- Jquery中AJAX参数详细介绍
Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ...
随机推荐
- python+uwsgi导致redis无法长链接引起性能下降问题记录
今天在部署python代码到预生产环境时,web站老是出现redis链接未初始化,无法连接到服务的提示,比对了一下开发环境与测试环境代码,完全一致,然后就是查看各种日志,排查了半天也没有查明是什么原因 ...
- javaScript中的小细节-script标签中的预解析
首先介绍预解析,虽然预解析字面意思很好理解,但是却是出坑出的最多的地方,也是bug经常会有的地方,利用好预解析的特性可以解决很多问题,并且提高代码的质量及数量,浏览器在解析代码前会把变量的声明和函数( ...
- iOS 小知识点(持续更新)
1.如何通过代码设置Button title的字体大小 设置Button.titleLabel.font = [UIFont systemFontOfSize:<#(CGFloat)#> ...
- ubuntu进行子域名爆破
好记性不如烂笔头,此处记录一下,ubuntu进行子域名的爆破. 先记录一个在线的子域名爆破网址,无意中发现,很不错的网址,界面很干净,作者也很用心,很感谢. https://phpinfo.me/do ...
- BZOJ 1006 【HNOI2008】 神奇的国度
题目链接:神奇的国度 一篇论文题--神奇的弦图,神奇的MCS-- 感觉我没有什么需要多说的,这里简单介绍一下MCS: 我们给每个点记录一个权值,从后往前依次确定完美消除序列中的点,每次选择权值最大的一 ...
- Orcale 三层嵌套分页代码
select * from( select emp.*,rownum a from ( select * from emp ) emp where rownum<7) where a>3
- 【流量劫持】SSLStrip 的未来 —— HTTPS 前端劫持
前言 在之前介绍的流量劫持文章里,曾提到一种『HTTPS 向下降级』的方案 -- 将页面中的 HTTPS 超链接全都替换成 HTTP 版本,让用户始终以明文的形式进行通信. 看到这,也许大家都会想到一 ...
- Linux.NET学习手记(6)
各位读者大家好,好长一段时间没有更新文章了,自从参加工作之后,每天等待去做的工作没完没了,个人的时间也变得奢侈起来,今后要尽量从中脱身,抽更多的时间来完成自己想做的事情(希望如此). 言归正传,上一回 ...
- 用Excel做出比肩任务管理软件的操作技巧
用Excel做出比肩任务管理软件的操作技巧 在项目管理中,网上有各种各样的工具可以选择,到底用哪个,曾一度困扰着我.我是一个有轻度强迫症的人,总是喜欢试用各种各样的系统,以比较他们之间的不同,试图选择 ...
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...