This article mainly introduces the Bootstrap Table search box and query function. It is very good and has reference value. Friends in need can refer to it. I hope it can help everyone.
1. Knowledge points bootstrapTable refresh and query configuration
2. Improve js code performance
1. Reduce global variable declarations
2. Cache dom Node search results
3. Local variables cache global variables
/** * @param col bootstrapTable列表生成配置对象 */ var searchValue ={};//查询匹配对象 var $button = $('<p class="columns pull-right search-button"><button class="btn btn-default" type="button" name="refresh" title="查询"><i class="glyphicon glyphicon-search icon-search"></i></button></p>'); var $input = $('<p class="columns pull-right search-input"><input class="form-control" type="text" placeholder="搜索"></p>'); var $select = $('<p class="columns pull-right search-select"><select></select></p>'); var addSearchGroup = function(col) { // 插入选项 var button ,input,select; button = $button;input = $input;select = $select;////局部变量缓存全局变量 提高代码性能 var selectDom = $select.find('select');////缓存dom节点查找结果 避免在循环里用 for(var i = 0; i < col.length; i++){ if(col[i].visible != false){ var $option = '<option value="'+col[i].field+'">'+col[i].title+'</option>'; selectDom.append($option); } } //插入多选框、输入框、按钮 $('.fixed-table-toolbar').append(button,input,select); } /* button = $button */ searchAction($button); function searchAction(button){ //写入上一次查询的条件 if(searchValue.select != undefined){ $select.find('select').val(searchValue.select); }; if(searchValue.input != undefined){ $input.find('input').val(searchValue.input); }; //写入查询条件 // 获取查询选项 button.click(function(){ var option = $select.find('select').val(); var inputval = $input.find('input').val(); searchValue.select =option; searchValue.inputval =inputval; //定义刷新参数 if(inputval != ''){ var param = { url: sWebRootPath+"/json/getAjaxData.jsp?v="+new Date().getTime(), query: { filters:[ {'colname':option,'filtertype':'LIKE','filtervalues':inputval} ] } } }else{ var param = { url: sWebRootPath+"/json/getAjaxData.jsp?v="+new Date().getTime(), } } // 刷新表格 $('#tablelist').bootstrapTable('refresh',param); }); }
Related recommendations:
Detailed explanation of how PHP implements a simple search box automatic prompt function
jquery implements a search box similar to Baidu
HTML implements a fixed floating semi-transparent search box on the mobile side
The above is the detailed content of Detailed explanation of Bootstrap Table search box and query function. For more information, please follow other related articles on the PHP Chinese website!