---恢复内容开始---

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:

  1. $('#example').dataTable(
  2. {
  3. data: [
  4. {
  5. "name":    "Tiger Nixon1",
  6. "position":   "System Architect1",
  7. "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
  8. "salary":    "$3,1201",
  9. "start_date": "2011/04/25",
  10. "office":    "Edinburgh1",
  11. "extn":    "54211"
  12. },
  13. {
  14. "name":    "Tiger Nixon2",
  15. "position":   "System Architect2",
  16. "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
  17. "salary":    "$3,1202",
  18. "start_date": "2011/04/25",
  19. "office":    "Edinburgh2",
  20. "extn":    "54212"
  21. },
  22. {
  23. "name":    "Tiger Nixon3",
  24. "position":   "System Architect3",
  25. "phone": { "plain": 5552368, "filter": "5552368 555-2368", "display": "555-2368" },
  26. "salary":    "$3,1203",
  27. "start_date": "2011/04/25",
  28. "office":    "Edinburgh3",
  29. "extn":    "54213"
  30. }
  31. ],
  32. columnDefs: [
  33. {
  34. "targets": 0,
  35. "searchable": false
  36. },
  37. {
  38. "targets": [1,2,3],
  39. "orderData": [ 2, 3, 4 ],
  40. "searchable": false
  41. },
  42. {
  43. "targets": [-3,-4],
  44. "orderable": false,
  45. "searchable": false
  46. }
  47. ],
  48. columns: [
  49. { "name": "name",
  50. "cellType": "th",
  51. "orderDataType": "dom-text",
  52. "orderSequence": [ "desc","asc", "asc" ],
  53. "className": "my_class",
  54. "contentPadding": "mmm",
  55. "createdCell": function (td, cellData, rowData, row, col) {
  56. if ( row < 1 ) {
  57. $(td).css('color', 'red');
  58. }
  59. },
  60. "data": "name",
  61. "searchable": true,
  62. "title": "My Name"
  63. },
  64. {
  65. "data": "position",
  66. "render": function ( data, type, full, meta ) {
  67. return '<a href="'+data+'">' + data + '</a>';
  68. }
  69. },
  70. {
  71. "data": 'phone',
  72. "render": {
  73. "_": "plain",
  74. "filter": "filter",
  75. "display": "display"
  76. }
  77. },
  78. { "data": "office" },
  79. { "data": "start_date", "type": "date" },
  80. { "data": "extn", "visible": false},
  81. { "data": "salary", "width": "20px"  },
  82. {
  83. "data": null,
  84. "orderable": false,
  85. "defaultContent": "<button>Edit</button>"
  86. }
  87. ]
  88. }
  89. );
参数详解:
用户参数名 源码参数名 英文解释 中文解释

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 参数详细说明的更多相关文章

  1. JQuery中的AJAX参数详细介绍

    Jquery中AJAX参数详细介绍 参数名 类型 描述 url String    (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方 ...

  2. JQuery插件datatables相关api

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

  3. jquery datatables api (转)

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

  4. 最全的jquery datatables api 使用详解

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

  5. jquery datatables api

    原文地址 学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/ ...

  6. Jquery Datatables 请求参数及接收参数处理

    Jquery Datatables 请求参数及接收参数处理 /** * Created by wb-wuyifu on 2016/8/9. */ /** * Created by wb-wuyifu ...

  7. 转载 Jquery中AJAX参数详细介绍

    Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ...

  8. Jquery中AJAX参数详细(1)-转

    http://www.cnblogs.com/qiufuwu618/archive/2012/12/20/2826190.html Jquery中AJAX参数详细列表: 参数名 类型 描述 url S ...

  9. Jquery中AJAX参数详细介绍

    Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ...

随机推荐

  1. 计算机程序的思维逻辑 (54) - 剖析Collections - 设计模式

    上节我们提到,类Collections中大概有两类功能,第一类是对容器接口对象进行操作,第二类是返回一个容器接口对象,上节我们介绍了第一类,本节我们介绍第二类. 第二类方法大概可以分为两组: 接受其他 ...

  2. UWP开发必备:常用数据列表控件汇总比较

    今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...

  3. 套用JQuery EasyUI列表显示数据、分页、查询

    声明,本博客从csdn搬到cnblogs博客园了,以前的csdn不再更新,朋友们可以到这儿来找我的文章,更多的文章会发表,谢谢关注! 有时候闲的无聊,看到extjs那么肥大,真想把自己的项目改了,最近 ...

  4. yaf的简单入门

    1.目录结构: 2.入口文件 入口文件是所有请求的入口,一般都借助于rewrite规则,把所有的请求都重定向到这个入口文件. 一个经典的入口文件  public/index.php 3.重写规则 需要 ...

  5. 开源 iOS 项目分类索引大全 - 待整理

    开源 iOS 项目分类索引大全 GitHub 上大概600个开源 iOS 项目的分类和介绍,对于你挑选和使用开源项目应该有帮助 系统基础库 Category/Util sstoolkit 一套Cate ...

  6. Zephyr OS 简介

    最新发布的开源 Zephyr Project™(Zephyr 项目)是一款小型且可伸缩的实时操作系统,尤其适用于资源受限的系统,可支持多种架构:该系统高度开源,对于开发人员社区完全开放,开发人员可根据 ...

  7. 喜马拉雅音频下载器 V1.2 支持专辑批量下载 喜马拉雅mp3下载导出 喜马拉雅下载器

    出差一个星期回来看邮箱,发现好多网友评论说网站又更新了,老程序不能用了,有热心网友放出修改版的,我就不重复造车了..大家可以去这里下载 http://blog.csdn.net/suqingheang ...

  8. Mono产品生命周期

    软件生命周期 同任何事物一样,一个软件产品或软件系统也要经历孕育.诞生.成长.成熟.衰亡等阶段,一般称为软件生命周期(软件生存周期) .软件生命周期模型是指人们为开发更好的软件而归纳总结的软件生命周期 ...

  9. APP漏洞扫描用地址空间随机化

    APP漏洞扫描用地址空间随机化 前言 我们在前文<APP漏洞扫描器之本地拒绝服务检测详解>了解到阿里聚安全漏洞扫描器有一项静态分析加动态模糊测试的方法来检测的功能,并详细的介绍了它在针对本 ...

  10. android内部培训视频_第五节(1)_OA实战之登录界面

    第五节(1):OA实战之登录界面  一.登录界面布局 1.背景图片 2.文本框 3.checkbox 4.按钮 暂未实现点击切换图片效果 <RelativeLayout xmlns:androi ...