search
HomeWeb Front-endJS TutorialJQuery.dataTables table plug-in jumps to the specified page example sharing

This article mainly introduces the JQuery.dataTables table plug-in to add a solution to jump to a specified page. It is very good and has reference value. Friends who need it can refer to it. I hope it can help everyone.

1. Solution

1. Add a custom toolbar and embed the text box

 "dom": 'lfrtip', //自定义工具栏 
//设置工具栏内容 
//l - length changing input control 
//f - filtering input 
//t - The table! 
//i - Table information summary 
//p - pagination control 
//r - processing display element 
[javascript] view plain copy print?
$("p.toolbar").html(' <b>跳转第</b><input><b>页</b>');

2. Listen to the change event of the text box and execute the plug-in's transfer page method

//调转到指定页面索引 ,注意大小写 
var oTable = $('#example1').dataTable(); 
oTable.fnPageChange(page);

3. After the plug-in is drawn successfully, the value of the bound text box

//绘制的时候触发,绑定文本框的值 
table.on('draw.dt', function (e, settings, data) { 
  var info = table.page.info(); 
  //此处的page为0开始计算 
  console.info('Showing page: ' + info.page + ' of ' + info.pages); 
 
  $('#searchNumber').val(info.page + 1); 
});

2. The complete sample code


 
   
     
       
       
       
       
       
     
   
编号姓名性别生日班级
  $(function () {    //注意方法名为DataTable    var table = $('#example1').DataTable({      "dom": 'lfrtip', //自定义工具栏      "pagingType": "full_numbers",      lengthMenu: [3, 5, 10],      processing: true,//是否使用进度条      serverSide: true,//是否启用数据库加载      ajax: {        url: '/tableone/getlist',        type: 'post',        data: function (d) {          d.name = '张三';          /*          * 自定义aja参数          * 特别说明,此处可以重写控件的默认参数,比如分页参数          */          // d.start = 0;          //console.info(d);          //var page = $('#searchNumber').val();          //page = parseInt(page) || 1;          //d.start = (page - 1) * d.length;        }      },      //指定列绑定的字段      columns: [        { data: 'sno' },        { data: 'sname' },        { data: 'ssex' },        { data: 'sbirthday' },        { data: 'class' }      ],      order: [        [3, 'desc']      ]    });    $("p.toolbar").html(' 跳转第');    //绑定分页事件----在切换分页的时候触发    //table.on('page.dt', function () {    //  var info = table.page.info();    //  console.info('Showing page: ' + info.page + ' of ' + info.pages);    //});    //绘制的时候触发,绑定文本框的值    table.on('draw.dt', function (e, settings, data) {      var info = table.page.info();      //此处的page为0开始计算      console.info('Showing page: ' + info.page + ' of ' + info.pages);      $('#searchNumber').val(info.page + 1);    });    //监听文本框更改    $('#searchNumber').change(function () {      var page = $(this).val();      page = parseInt(page) || 1;      page = page - 1;      //调转到指定页面索引 ,注意大小写      var oTable = $('#example1').dataTable();      oTable.fnPageChange(page);    });  });

is displayed as follows:

Related recommendations:

jQuery plug-in DataTables paging development technology sharing

Solution to jQuery Datatables header misalignment

Introduction to jquery plug-in datatables attributes and detailed explanations of creating paging and sorting examples

The above is the detailed content of JQuery.dataTables table plug-in jumps to the specified page example sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Java vs JavaScript: A Detailed Comparison for DevelopersJava vs JavaScript: A Detailed Comparison for DevelopersMay 16, 2025 am 12:01 AM

JavaandJavaScriptaredistinctlanguages:Javaisusedforenterpriseandmobileapps,whileJavaScriptisforinteractivewebpages.1)Javaiscompiled,staticallytyped,andrunsonJVM.2)JavaScriptisinterpreted,dynamicallytyped,andrunsinbrowsersorNode.js.3)JavausesOOPwithcl

Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool