English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
1configuração padrão do DataTables
$.document.ready(function() { $('#example').dataTable(); });
Exemplo:http://www.guoxk.com/html/DataTables/Zero-configuração.html
2configurações básicas do DataTables
"bPaginate": true, //função de navegação
"bLengthChange": true, //mudar o número de itens por página
"bFilter": true, //função de filtro
"bSort": false, //função de classificação
"bInfo": true,//informações de rodapé
"bAutoWidth": true//largura automática
Exemplo:http://www.guoxk.com/html/DataTables/Funcionalidade-enablement.html
3ordenar dados
$.document.ready(function() { $('#example').dataTable({ "aaSorting": [ [ 4, "desc" ] ] }); });
começando pela coluna4ordenar colunas em ordem inversa
Exemplo:http://www.guoxk.com/html/DataTables/Ordenação-data.html
4ordenar por várias colunas
Exemplo:http://www.guoxk.com/html/DataTables/Multi-coluna-sorting.html
5ocultar algumas colunas
$.document.ready(function() { $('#example').dataTable({ "aoColumnDefs": [ {"bSearchable": false, "bVisible": false, "aTargets": [ 2 ]} , {"bVisible": false, "aTargets": [ 3 ]) ]) ); });
Exemplo:http://www.guoxk.com/html/DataTables/Oculto-columns.html
6mudar a posição dos elementos na página
$.document.ready(function() { $('#example').dataTable({ "sDom": '<"top"fli>rt<"bottom"p><"clear">' }); }); //l- Número de itens por página //f – Entrada de filtro //t – Tabela de formulário //i – 信息 //p – 翻页 //r – pRocessing //< and > – div elements //<"class" and > – div with a class //Examples: <"wrapper"flipt>, <lf<tip>
Exemplo:http://www.guoxk.com/html/DataTables/DOM-positioning.html
7、状态保存,使用了翻页或者改变了每页显示数据数量,会保存在cookie中,下回访问时会显示上一次关闭页面时的内容。
$.document.ready(function() { $('#example').dataTable({ "bStateSave": true }); });
Exemplo:http://www.guoxk.com/html/DataTables/State-saving.html
8、显示数字的翻页样式
$.document.ready(function() { $('#example').dataTable({ "sPaginationType": "full_numbers" }); });
Exemplo:http://www.guoxk.com/html/DataTables/Alternative-pagination-styles.html
9、水平限制宽度
$.document.ready(function() { $('#example').dataTable({ "sScrollX": ""100% "sScrollXInner": ""110% "bScrollCollapse": true }); });
Exemplo:http://www.guoxk.com/html/DataTables/Horizontal.html
10、垂直限制高度
Exemplo:http://www.guoxk.com/html/DataTables/Vertical.html
11、水平和垂直两个方向共同限制
Exemplo:http://www.guoxk.com/html/DataTables/HorizontalVerticalBoth.html
12、改变语言
$.document.ready(function() { $('#example').dataTable({ "oLanguage": { "sLengthMenu": "每页显示 _MENU_ 条记录" "sZeroRecords": "抱歉, 没有找到" "sInfo": "从 _START_ 到 _END_" /共 _TOTAL_ 条数据 "sInfoEmpty": "没有数据" "sInfoFiltered": "(从 _MAX_ 条数据中检索)" "oPaginate": { "sFirst": "首页" "sPrevious": "前一页" "sNext": "后一页" "sLast": "尾页" } "sZeroRecords": "没有检索到数据" "sProcessing": "<img src=\'#\'" /loading.gif' /"> } }); });
Exemplo:http://www.guoxk.com/html/DataTables/Change-language-information.html
13、click事件
Exemplo:http://www.guoxk.com/html/DataTables/event-click.html
14/配合使用tooltip插件
Exemplo:http://www.guoxk.com/html/DataTables/tooltip.html
15、定义每页显示数据数量
$.document.ready(function() { $('#example').dataTable({ "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]] }); });
Exemplo:http://www.guoxk.com/html/DataTables/length_menu.html
16callback de linha
Exemplo:http://www.guoxk.com/html/DataTables/RowCallback.html
O valor da última coluna é destacado se for "A"
17controle de ordenação
$.document.ready(function() { $('#example').dataTable({ "aoColumns": [ null, {"asSorting": ["asc"]}, {"asSorting": ["desc", "asc", "asc"]}, {"asSorting": []}, {"asSorting": []} ] }); });
Exemplo:http://www.guoxk.com/html/DataTables/sort.html
Anotação: a primeira coluna é ordenada por padrão ao clicar, a segunda coluna é ordenada ao clicar, a terceira coluna é invertida ao clicar uma vez, e a segunda vez é ordenada, e a terceira vez é ordenada, as colunas 4 e 5 não implementam ordenação ao clicar
18usando pacotes de idioma lidos do arquivo de configuração
$.document.ready(function() { $('#example').dataTable({ "oLanguage": { "sUrl": "cn.txt" } }); });
19usando a fonte ajax
$.document.ready(function() { $('#example').dataTable({ "bProcessing": true, "sAjaxSource": "."/arrays.txt' }); });
Exemplo:http://www.guoxk.com/html/DataTables/ajax.html
20. Usar ajax para organizar dados no servidor
$.document.ready(function() { $('#example').dataTable({ "bProcessing": true, "bServerSide": true, "sPaginationType": "full_numbers", "sAjaxSource": "."/server_processing.php", /*Se adicionado o seguinte conteúdo, os dados serão transmitidos pelo método POST "fnServerData": function (sSource, aoData, fnCallback) { $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback }); }*/ "oLanguage": { "sUrl": "cn.txt" } "aoColumns": [ {"sName": "platform" }, {"sName": "version" }, {"sName": "engine" }, {"sName": "browser" }, {"sName": "grade" } ]//$_GET['sColumns'] receberá os dados transmitidos por aoColumns }); });
Exemplo:http://www.guoxk.com/html/DataTables/ajax-serverSide.html
21carregar id e class para cada linha
O formato dos dados retornados pelo servidor é:
{"}} "DT_RowId": "row_"8"., "DT_RowClass": "gradeA" "0": "Gecko" "1": "Firefox" 1.5"., "2": "Win" 98+ / OSX.2+" "3": "1.8"., "4": "A" }
Exemplo:http://www.guoxk.com/html/DataTables/add_id_class.html
22、Mostrar detalhes em cada linha, clicando no início da linha "+Mostrar detalhes ao expandir com "
Exemplo:http://www.guoxk.com/html/DataTables/with-row-information.html
23、Selecionar várias linhas
Exemplo:http://www.guoxk.com/html/DataTables/selectRows.html
22、Integração do plugin jQuery jEditable
Exemplo:http://www.guoxk.com/html/DataTables/jEditable-integration.html
Mais referências:
Atenção: O objeto table que será processado pelo dataTable deve ter thead e tbody, e a estrutura deve ser regular (os dados não precisam ser completos), para que o processamento seja correto.
Aqui estão os parâmetros que podem ser adicionados ao binding do dataTable:
Aqui está uma explicação detalhada do uso do plugin jQuery.datatables.js e exemplos de API, esperando ajudar os usuários. Se você tiver alguma dúvida, por favor, deixe um comentário, eu responderi o mais rápido possível. Agradecemos também o apoio ao site Tutorial Yell!
Declaração: O conteúdo deste artigo é extraído da Internet, pertence ao respectivo proprietário e foi carregado voluntariamente pelos usuários da Internet. Este site não possui direitos de propriedade, não foi editado manualmente e não assume responsabilidades legais relacionadas. Se você encontrar conteúdo suspeito de violação de direitos autorais, por favor, envie um e-mail para: notice#oldtoolbag.com (ao enviar e-mail, substitua # por @ para denunciar e forneça provas relevantes. Caso seja confirmado, o site deletará imediatamente o conteúdo suspeito de violação de direitos autorais.)