jQuery插件:DataTables简单示例

DataTables插件零配置使用示例:

HTML代码


[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]



在上图可以看到,DataTables插件为table添加了额外的5个功能:每页记录数、搜索、排序、信息及分页。

一、5个功能基本设置

1.每页记录数

$("#example").dataTable({
    "bLengthChange": true,
    "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
    "iDisplayLength": 10
});

说明:必须bPaginate=true时,bLengthChange=true才能显示。

2.搜索

$("#example").dataTable({
    "bFilter": true
});

3.排序

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

4.信息

$("#example").dataTable({
    "bInfo": true
});

5.分页

$("#example").dataTable({
    "bPaginate": true,
    "sPaginationType": "full_numbers" //two_button (default) and full_numbers
});

二、5个功能全局设置

$.extend($.fn.dataTable.defaults, {
    "bLengthChange": false,
    "bFilter": false,
    "bSort": false
});    
$("#example").dataTable();

三、5个功能位置调整

$("#example").dataTable({
    "sDom": 'iptlf'
});

sDom属性值具体含义:

·l - Length changing
·f - Filtering input
·t - The table!
·i - Information
·p - Pagination
·r - pRocessing
·< and > - div elements
·<"class" and > - div with a class

四、5个功能语言设置

$("#example").dataTable({
    "oLanguage": {
        "sLengthMenu": "Display _MENU_ records per page",
        "sZeroRecords": "Nothing found - sorry",
        "sSearch": "Search all columns:",
        "sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
        "sInfoEmpty": "Showing 0 to 0 of 0 records",
        "sInfoFiltered": "(filtered from _MAX_ total records)",
        "oPaginate": {
            "sFirst": "First",
            "sPrevious": "Previous",
            "sNext": "Next",
            "sLast": "Last"
        }
    }
});


评论: 0 | 引用: 0 | 查看次数: 6045
发表评论
登录后再发表评论!