---
title: "JQuery Datatables 学习笔记(二)-customer set the option at inint time"
author: "boyatec"
date: "2010-08-27T16:54:02Z"
tags: []
categories: ["Web前端"]
slug: "jquery-datatables-customer-set-the-option-at-inint-time"
draft: false
lastmod: "2010-08-27T16:54:02Z"
id: 749149
url: "https://boyatec.iteye.com/blog/749149"
---

review:上一节，简要描叙了DT的作用，如何插入到页面当中，基本功能构造，etc。这一节主要围绕基本功能，用户配置适合自己的相关参数满足需要。

**1、排序方面:(bSort)**

when bSort Set be true，可以在初始表格时，指定哪些列如何排序，以及排序的方向，通过aaSorting这个property可以实现

```
$("#tableid").dataTable({"bSort":true,"aaSorting":[[0,"asc"][1,"desc"]]});
```

 表格初始化时先对第一行升序排，然后第二行降序排.

**2、Filter方面**

过滤，即find.初始化时pass a keywords to filter the table.使用aoSearchCols和oSearch两个参数定义.

oSearch站在全局的高度搜索，而aSearchCols是对ividial column define。例子

```
$("#tableid").dataTable({
"bFilter":true,
"oSearch":{"sSearch":"keyword1 keyword2 keyword3 ...","bRegex":true}
})
```

 sSearch:must provide.

bRegex:false|true(optional)

上面执行结果是在初始化时datatable查找key1,key2,key3...

```
$("#tableid").dataTable({
"aoSearchCols":[null,
{"sSearch":"keyword","bRegex":true}
null,
{"sSearch":"keyword2",bRegex":false}
]});
```

 aoSearchCols更像是aoColumns的定义，用于初始化时定义单列的查找关键字，注意:aoSearchCols**数组长度必须和表格列数相同。**

**3、每页显示长度下拉列表框(bLengthChange)/分页符(bPaginate)**

     iDisplayLenth:初始化时一页显示的列数(10,25,50,75,100,125,...-1)

     iDisplayStart:record offset，第一行显示的行数，默认情况是第一行。。。。

     aLengthMenu:定义下拉列表框的value和option。可以是1D,alse 2D&lt;select&gt;&lt;option&gt;&lt;/option&gt;&lt;/select&gt;

    

```
$("#tableid").dataTable({
"iDispalyLenth":-1,//显示所有的记录.
"iDisplayStart":50,//从第50行开始显示.
"aLengthMenu":[-1,10,25,50]["all","十","二十五","五十"],
"sPagination":"two_button"|"full_numbers"
})
```

**4、页面布局（sDom）**

sDom:"&lt;""flipt&gt;', 'ip&gt;'"

The following options are allowed:

- 'l' - Length changing //下拉列表框（长度 ）
- 'f' - Filtering input //搜索框
- 't' - The table! //表格数据
- 'i' - Information //information
- 'p' - Pagination //分页表
- 'r' - pRocessing //进度条

The following constants are allowed: 在JQueryUI中使用

- 'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix') //表格头
- 'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix') //表尾

 

The following syntax is expected:

- '&lt;' and '&gt;' - div elements //使用div
- '&lt;"class" and '&gt;' - div with a class //使用类

**4、其他方面**

.bDestroy(删除匹配原先的DT，然后用新的参数构建一个新的)