DataTables is a jQuery table plug-in. This is a highly flexible tool based on progressive enhancements that will add advanced interactive controls and support for any HTML form.
Official website and download address: http://www.datatables.net
The latest version is 1.10.2, readers can click here Download this site.
The main features are as follows:
1. Automatic paging processing
2. Instant table data filtering
3. Data sorting and automatic detection of data types
4. Automatically handle column width
5. Styles can be customized through CSS
6.Support hidden columns
7.Easy to use
8. Scalability and flexibility
9.Internationalization
10. Dynamically create tables
11. Free
How to use:
First look at the following code:
<title>DataTables example</title> <style type="text/css" title="currentStyle"> @import "../../media/css/demo_page.css"; @import "../../media/css/demo_table.css"; @import "../examples_support/themes/smoothness/jquery-ui-1.7.2.custom.css"; </style> <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script> <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script> <script type="text/javascript" charset="utf-8">
Introduce js and css files into the above code. It can be copied in the demo. Pay attention to the path address.
Let’s take a look at the following code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#example').dataTable( { "oLanguage": { "sUrl": "/SSS/dataTables/de_DE.txt" }, "bStateSave": true, //"bJQueryUI": true, //使用jqueryui 。我用的时候显示的不是很好 "sPaginationType": "full_numbers"//分页 } ); } ); </script> </head> <body id="dt_example">//此处为body的id <div id="container" align="center">//*div 里是 table ,table包括thead等,最好按此格式写* <h1 id="物品种类管理">物品种类管理</h1> <div id="demo"> <table cellpadding="5" cellspacing="0" border="1" class="display" id="example" align="center">//id 别忘了 <thead> <tr> <th>物品编号</th> <th>物品名称</th> <th>物品单位</th> <th>编辑状态</th> <th>随便</th> </tr> </thead> <tr class="gradeX">//此处可以是gradeA ,gradeX 等,但是gradeB 隔行换色 效果很好 <td>Trident</td> <td>Internet Explorer 4.0</td> <td>Win 95+</td> <td class="center">4</td> <td class="center">X</td> </tr> <tr class="gradeC"> <td>Trident</td> <td>Internet Explorer 5.0</td> <td>Win 95+</td> <td class="center">5</td> <td class="center">C</td> </tr> <tr class="gradeA"> <td>Trident</td> <td>Internet Explorer 5.5</td> <td>Win 95+</td> <td class="center">5.5</td> <td class="center">A</td> </tr> </tbody> <tfoot> </tfoot> </table> </div> </div>
The above can create the effect as shown in the picture, pagination. Sort. etc.
Finally, let’s talk about each attribute (the main location to add)
//$(document).ready(function() { //$('#example').dataTable( {//加载 //"bPaginate": true,//分页按钮 //"bLengthChange": true,//每行显示记录数 //"bFilter": true,//搜索栏 //"bSort": true,//排序 //"bInfo": true,//Showing 1 to 10 of 23 entries 总记录数没也显示多少等信息 //"bAutoWidth": true } ); //} ); //$(document).ready(function() { //$('#example').dataTable( { //"aaSorting": [[ 4, "desc" ]]//给列表排序 ,第一个参数表示数组 。4 就是css grade那列。第二个参数为 desc或是asc //} ); //} ); //$(document).ready(function() { //$('#example').dataTable( { //"aoColumns": [ // /* Engine */ null, //默认 // /* Browser */ null, // /* Platform */ { "bSearchable": false, //不可参与搜索 // "bVisible": false },//不可见 // /* Version */ { "bVisible": false },//不可见 // /* Grade */ null //] } ); //} ); //$(document).ready(function() { //$('#example').dataTable({ //}); //} ); //$(document).ready(function() { //$('#example').dataTable( { //"sDom": '<"top"i>rt<"bottom"flp<"clear">'//这段是自定义布局没搞明白挺复杂的。 * l - Length changing * f - Filtering input* t - The table!* i - Information* p - Pagination* r - pRocessing* < and > - div elements* <"class" and > - div with a class * Examples: <"wrapper"flipt>, <lf<t>ip> //} ); //} ); //$(document).ready(function() { // $('#example').dataTable( { // "bStateSave": true //保存状态到cookie *************** 很重要 , 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了 //} ); //} ); //$(document).ready(function() { //$('#example').dataTable( { //"sPaginationType": "full_numbers" //分页,一共两种样式 另一种为two_button 是datatables默认 //} ); //} ); //$(document).ready(function() { //$('#example').dataTable( { //分页信息 不是很难理解。 //"oLanguage": { //"sLengthMenu": "Display _MENU_ records per page", //"sZeroRecords": "Nothing found - sorry", //"sInfo": "Showing _START_ to _END_ of _TOTAL_ records", //"sInfoEmtpy": "Showing 0 to 0 of 0 records", //"sInfoFiltered": "(filtered from _MAX_ total records)" //} //} ); //} ) $(document).ready(function() { oTable = $('#example').dataTable({ "bJQueryUI": true, //可以添加 jqury的ui theme 需要添加css "sPaginationType": "full_numbers" }); } );
The default language is English, of course it can be internationalized:
"sUrl": "/SSS/dataTables/de_DE.txt" Just add an internationalized file. The name can be anything as long as the path is correct. The content of the internationalization file I wrote is as follows, which can be directly copied to txt for use.
{ "sProcessing": "Bitte warten...", "sLengthMenu": "显示_MENU_条 ", "sZeroRecords": "没有您要搜索的内容", "sInfo": "从_START_ 到 _END_ 条记录——总记录数为 _TOTAL_ 条", "sInfoEmpty": "记录数为0", "sInfoFiltered": "(全部记录数 _MAX_ 条)", "sInfoPostFix": "", "sSearch": "搜索", "sUrl": "", "oPaginate": { "sFirst": "第一页", "sPrevious": " 上一页 ", "sNext": " 下一页 ", "sLast": " 最后一页 " } }
These are the basic parts of datatables. Relatively easy to master.
I hope this article will be helpful to everyone’s learning of jQuery programming.

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
