Premise: Customize the search and have paging capabilities, such as searching for product names.
Phenomenon: When searching for inflatable dolls, return 100 records and turn to page fifth. At this time to search the massage stick, the data has 200, the results should be the first page of records, but the actual display is the result of the fifth page. That is, after re-searching, the pagenumber has not changed.
According to most of the Internet: Re-set option on the line
$ (' #tableList '). Bootstraptable ({pagenumber:1,pagesize:10});
The above is not a solution to this problem.
The right approach is
$ ("#table"). Bootstraptable (' destroy '); Destroy table first, otherwise the last loaded content will be preserved
Tableobj.otableinit (); Re-initialize the table.
All JS
<script type= "Text/javascript" > $(function() {tableobj.otableinit (); $("#btn_query"). Click (function () { $("#tb_departments"). Bootstraptable (' Destroy '); Tableobj.otableinit (); }); $("#btn_edit"). Click (function() {$.messager.alert (' Hint ', ' Please select a record to delete '); }); $("#btn_add"). Click (function () { varActionURL = "@Url. Action (" _create ")"; varparam = {}; Tool.showmodal (ActionURL, param,New); }) }); varTableobj = { //Initialize TableOtableinit:function () { $(' #tb_departments '). bootstraptable ({URL:'/department/getdepartment ',//URL to request background (*)Method: ' Get ',//Request Method (*)Toolbar: ' #toolbar ',//which container the tool button usesStriped:true,//whether to display line spacing colorsCachefalse,//whether to use the cache, the default is true, so it is generally necessary to set this property (*)Pagination:true,//whether to show pagination (*)Sortable:false,//whether to enable sortingSortOrder: "ASC",//Sorting Method //QueryParams:TableObj.queryParams (this),//Pass parameters (*)Queryparams:function(params) {return{pagedindex: This. PageNumber, Pagedsize: This. PageSize, Deptname: $ ("#txt_search_departmentname"). Val (),}; }, Sidepagination:"Server",//Paging method: Client clients paging, Server service end Paging (*)Pagenumber:1,//Initialize load first page, default first pagePagesize:5,//number of record lines per page (*)PageList: [5, 10, 25, 50, 100],//number of rows per page to choose from (*)Searchfalse,//whether to display a table search, this search is a client-side search, not into the server, so the personal sense of little meaningStrictsearch:true, Showcolumns:true,//whether to show all columnsShowrefresh:true,//whether to display the refresh buttonMinimumcountcolumns:2,//minimum allowable number of columnsClicktoselect:true,//whether to enable clicking on the selected rowHEIGHT:500,//row height, if the Height property is not set, the table automatically finds the table height according to the number of record barsUniqueId: "DeptID",//Unique identification of each row, typically primary key columnIDfield: ' DeptID ', Showtoggle:true,//whether to display the toggle buttons for the Detailed view and the list viewCardView:false,//whether to show the detailed viewDetailView:false,//whether to show parent-child tablescolumns: [{//field: ' DeptID ', //field: ' DeptID ',CheckBoxtrue}, {field:' Deptname ', Title:' Department name '}, {field:' CreateBy ', Title:' Add people '}, {field:' Createdt ', Title:' Add Date ', Formatter:function(val) {returnval = = ' Undefined ' | | !val? '-': val.formatterstring (false); } } ] }); } }; //Save functionSave () {Tool.savemodal ($ (' #tb_departments ')); } </script>
View Code
Bootstrap table pagination, re-search issues