jquery DataTables is used as our data table component in the project, but the pagination does not jump to the specified page and needs to be re-written. Here's how to fix it:
Set the default property of DataTables set its Drawcallback method to stitch The jump element behind, this method is DataTables 1.10 later version
This code is for the spring MyBatis pagehelper plug-in returned by the PageInfo for processing, the return structure is {success:true, data:pageinfo}, if you just look at the custom jump, Just look inside the Drawcallback method
/** * Set the default properties of the jquery dataTables */function set_default_datatables () {var language = {//Han "Processing": "In process. . "," Lengthmenu ":" Show _menu_ results "," zerorecords ":" No Matching results "," info ":" Show the results from _start_ to _end_, total _total _ Bar "," Infoempty ":" showing No. 0 to No. 0 results, total 0 "," infofiltered ":" (Filtered by _max_ results) "," Infopostfix ":" ", "Search": "Searching:", "url": "", "emptytable": "Data in table is empty", "loadingrecords": "Loading ...", "thousands": ",", "paginate": {"first": "Home", "previous": "Previous Page", "Next": "Next Page", "L AST ":" Last "}}; $.extend ($.fn.datatable.defaults, {searching:false, Ordering:false, Language:language, Len Gthchange:false, Lengthmenu, pagelength:15, Serverside:true, Pagingtyp, [5, ten, $, +] E: "Full_numbers", Ajax: {data:function (param) {Init_datatables_defaultparam (param); }, Datasrc:function (Result) {if (result.success) {var pageInfo = Result.d Ata Result.recordstotal = Pageinfo.total; result.recordsfiltered = Pageinfo.total; Tablerowcount = PageInfo.list.length; return pageinfo.list; } else {result.recordstotal = 0; result.recordsfiltered = 0; return []; }}}, Drawcallback:function (setting) {var _this = $ (this); var tableId = _this.attr (' id '); var pagediv = $ (' # ' + tableId + ' _paginate '); Pagediv.append (' Jump to <input id= ' + tableId + ' _gotopage ' type= ' text ' style= ' height:28px;line-height:28px ; width:40px; " /> ' + ' <a class= "Paginate_button" aria-controls= "' + tableId + '" tabindex= "0" id= "' + tableId + ' _go To "> OK </a> ') $ (' # ' + tableId + ' _goto '). Click (function (obj) {var page = $ (' # ' + tableId + ' _gotopage '). Val (); var thisdatatable = $ (' # ' + tableId). DataTable (); var pageInfo = ThisDataTable.page.info (); if (IsNaN (page)) {$ (' # ' + tableId + ' _gotopage '). Val ("); Return } else {var maxPage = pageinfo.pages; var page = number (page)-1; if (Page < 0) {page = 0; } else if (page >= maxPage) {page = maxPage-1; } $ (' # ' + tableId + ' _gotopage '). val (page + 1); Thisdatatable.page (page). Draw (' page '); } }) } });} /** * Remove dataTables default parameter and set paging value * @param param */function init_datatables_defaultparam (param) {for (var key in param) { if (Key.indexof ("CoLumns ") = = 0 | | Key.indexof ("order") = = 0 | | Key.indexof ("search") = = 0) {//delete the delete Param[key] with the parameters beginning with columns; }} param.pagesize = Param.length; Param.pagenum = (param.start/param.length) + 1;}
jquery DataTables Add jump to specified page features