bootstrap table 前端搜索
1.bootstrap-table对于前端的搜索可以通过官网设置,但发现前端搜索出现bug,网上找到一个bootstrap-table的扩充js bootstrap-table-mytoolbar.js,可以通过结合bootstrap-table简单的配置就可以进行使用,结合实例说明:
bootstrap-table的扩充js内容:
/**
* @author: aperez <aperez@datadec.es>
* @version: v2.0.0
*
* @update Dennis Hernández <http://djhvscf.github.io/Blog>
*/ !function($) {
'use strict'; var firstLoad = false; var sprintf = $.fn.bootstrapTable.utils.sprintf; var showAvdSearch = function(that) {
var timeoutId=0;
$('#'+ that.options.idTable).off('keyup blur', 'input').on('keyup blur', 'input', function (event) {
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
that.onColumnAdvancedSearch(event);
}, that.options.searchTimeOut);
});
}; $.extend($.fn.bootstrapTable.defaults, {
advancedSearch: false,
actionForm: '',
idTable: undefined,
onColumnAdvancedSearch: function (field, text) {
return false;
}
}); $.extend($.fn.bootstrapTable.defaults.icons, {
advancedSearchIcon: 'glyphicon-chevron-down'
}); $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'column-advanced-search.bs.table': 'onColumnAdvancedSearch'
}); $.extend($.fn.bootstrapTable.locales, {
formatAdvancedSearch: function() {
return 'Advanced search';
},
formatAdvancedCloseButton: function() {
return "Close";
}
}); $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales); var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initToolbar = BootstrapTable.prototype.initToolbar,
_load = BootstrapTable.prototype.load,
_initSearch = BootstrapTable.prototype.initSearch; BootstrapTable.prototype.initToolbar = function() {
_initToolbar.apply(this, Array.prototype.slice.apply(arguments)); /*if (!this.options.search) {
return;
}*/ if (!this.options.advancedSearch) {
return;
} if (!this.options.idTable) {
return;
} var that = this;
showAvdSearch(that);
}; BootstrapTable.prototype.load = function(data) {
_load.apply(this, Array.prototype.slice.apply(arguments)); if (!this.options.advancedSearch) {
return;
} if (typeof this.options.idTable === 'undefined') {
return;
} else {
if (!firstLoad) {
var height = parseInt($(".bootstrap-table").height());
height += 10;
$("#" + this.options.idTable).bootstrapTable("resetView", {height: height});
firstLoad = true;
}
}
}; BootstrapTable.prototype.initSearch = function () {
_initSearch.apply(this, Array.prototype.slice.apply(arguments)); if (!this.options.advancedSearch) {
return;
} var that = this;
var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial; this.data = fp ? $.grep(this.data, function (item, i) {
for (var key in fp) {
var fval = fp[key].toLowerCase();
var value = item[key];
value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header,
that.header.formatters[$.inArray(key, that.header.fields)],
[value, item, i], value); if (!($.inArray(key, that.header.fields) !== -1 &&
(typeof value === 'string' || typeof value === 'number') &&
(value + '').toLowerCase().indexOf(fval) !== -1)) {
return false;
}
}
return true;
}) : this.data;
}; BootstrapTable.prototype.onColumnAdvancedSearch = function (event) {
var text = $.trim($(event.currentTarget).val());
var $field = $(event.currentTarget)[0].id; if ($.isEmptyObject(this.filterColumnsPartial)) {
this.filterColumnsPartial = {};
}
if (text) {
this.filterColumnsPartial[$field] = text;
} else {
delete this.filterColumnsPartial[$field];
} this.options.pageNumber = 1;
this.onSearch(event);
this.updatePagination();
this.trigger('column-advanced-search', $field, text);
}; }(jQuery);
配置bootstrap-table的js文件:
$("#listTable").bootstrapTable({
columns:[
{
title: '序号',
align: 'center',
valign: 'bottom',
//field : 'id',
formatter:function(value,row,index){
return index+1;
}
},{
title: '客户ID',
align: 'center',
field: 'orgId',
visible: false
},{
title : '客户名称',
align : 'center',
field : 'orgName',
searchable : true
},{
title : '户号',
align : 'center',
field : 'account_num'
},{
title : '月份',
align : 'center',
field : 'ele_date'
},{
title : '用电量需求(单位:兆瓦时)',
align : 'center',
field : 'ele_need_mount'
},{
title : '意向成交价差 (单位:元/兆瓦时)',
align : 'center',
field : 'intent_ele_price'
},{
title : '查看',
align : 'center',
field : 'fj'
}],
striped: true, //隔行变色
strictSearch: true,
clickToSelect: true,
cache:false,
showRefresh: true,
pagination: false,
pageNumber:1,
pageSize: 15,
pageList: [5, 10, 15, 20, 25],
showExport: true,//显示导出按钮
exportDataType: "basic",//导出类型
sidePagination: "client",
advancedSearch:true,//允许外部搜索 这个是扩充的js里面的属性
56 idTable:"abc",//搜索input的父级id
searchOnEnterKey:false,
strictSearch:false,
queryParamsType : "limit",
//search : true,
// searchText : "客户名称",
//toolbar: '#toolbar',
data:tableData
});
//search下面的内容除了选择器都是固定的
$("#listTable").on('post-body.bs.table', function () {
//debugger;
console.log($("#listTable").data);
var $search = $("#listTable").data('bootstrap.table').$toolbar.find('.search input');
$search.attr('placeholder', '客户名称');
$search.parents(".fixed-table-toolbar").css({position:'absolute',top: '-53px',right: '16px'});
});
});
对应的html页面是:
<div class="row">
<div class="ibox-title">
<h5>
<i class="fa fa-sitemap"></i> 月度交易结果分配详情列表 <span class='sfont'>(电量单位:兆瓦时
)</span>
</h5>
<div class="fright" style="margin-top: -8px;">
<button class="btn btn-w-m btn-primary editBtn" type="button" style="margin-right: 5px;"
id="edit_btn_input" ng-click="editOperater()">编辑</button>
<span class="tit_inputbox" id="abc"> <input type="text" //这里的id值是abc 和bootstrap-table设置的需要一样
id="orgName" placeholder="客户名称" />
</span>
</div>
</div>
<div class="col-md-12 ibox-content">
<table
class="table table-striped table-bordered table-hover dataTables-example"
id="sitemap_table"></table>
</div>
</div>
bootstrap table 前端搜索的更多相关文章
- Bootstrap table前端分页(ssm版)
说明bootstrap table可以前端分页,也可以后端sql用limit分页.前端分页下性能和意义都不大,故一般情况下不用这种,请看我的另一篇后端分页的博客源码下载地址:https://git.o ...
- BootStrap table 传递搜索参数
看bootStrap table文档不难发现它有一个queryparams属性,是向后台传递参数的,默认参数已有pageSize.pageIndex等,那么怎么传递自定义的参数呢?在网上找了好多也没有 ...
- bootstrap table 插件 搜索
以前用过easyui datagrid 每次搜索的时候调用datagrid构造方法 重新获取数据, 发现bootstrap-table 插件不行,只需要初始化一次, 以后每次搜索时,直接调用refre ...
- bootstrap table + spring + springmvc + mybatis 实现从前端到后端的表格分页
1.使用准备 前台需要的资源文件,主要有Bootstrap3相关css.js以及bootstrap Table相关css.js: <-- 样式 --> <link rel=" ...
- js实现table中前端搜索(模糊查询)
项目中用到js前端搜索功能,根据 姓名或姓名 进行 搜索,实现方法如下,遍历table所有行中的某列,符合条件则置tr为display:'',不满足条件置tr为display:none. 代码如下: ...
- [前端插件]Bootstrap Table服务器分页与在线编辑应用总结
先看Bootstrap Table应用效果: 表格用来显示数据库中的数据,数据通过AJAX从服务器加载,同时分页功能有服务器实现,避免客户端分页,在加载大量数据时造成的用户体验不好.还可以设置查询数据 ...
- 轻量级表格插件Bootstrap Table。拥有强大的支持固定表头、单/复选、排序、分页、搜索及自定义表头等功能。
Bootstrap Table是轻量级的和功能丰富的以表格的形式显示的数据,支持单选,复选框,排序,分页,显示/隐藏列,固定标题滚动表,响应式设计,Ajax加载JSON数据,点击排序的列,卡片视图等. ...
- 如何将自定义的搜索参数便捷的添加到js方式的bootstrap table的参数中
页面: <div> <form id="exp_form"> 查询参数... <button type="button" oncl ...
- BootStrap table使用
bootstrap table git address https://github.com/wenzhixin/bootstrap-table 引入文件 <link rel="sty ...
随机推荐
- 离线在MVC4中的使用
最近在项目中用到了离线功能,自己感觉挺高端的,但是遇到了一些问题. 现在工作告一小段落,就把这次离线工作中遇到的关键技术点和难题记录下来. 什么是离线,什么时候需要离线 离线:Offline,不联网也 ...
- Spring IOC(二)beanName 别名管理
Spring IOC(二)beanName 别名管理 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.AliasReg ...
- Redis学习笔记:windows上redis的安装运行
Redis的windows版本地址https://github.com/MicrosoftArchive/redis 下载之后解压之 在当前解压目录下可以看到如下文件 在当前目录下打开命令行窗口,输入 ...
- Python之字符串基本操作
#!/usr/bin/env python#-*-coding utf8-*-#Author:caojininfo = { 'stu1001': 'caojin', 'stu1002': 'zhaom ...
- php 超时设置笔记
php.ini default_socket_timeout=5 mysql.connect_timeout = 5 max_execution_time = 5 php-fpm pm = dynam ...
- 2018.12.22 bzoj3473: 字符串(后缀自动机+启发式合并)
传送门 调代码调的我怀疑人生. 启发式合并用迭代写怎么都跑不过(雾 换成了dfsdfsdfs版本的终于过了233. 题意简述:求给出nnn个字串,对于每个给定的字串求出其有多少个字串在至少kkk个剩下 ...
- (16)The beauty of what we'll never know
https://www.ted.com/talks/pico_iyer_the_beauty_of_what_we_ll_never_know/transcript 00:13One hot Octo ...
- Amaze UI 云适配
Amaze UI 云适配 陈本峰 一中,中科大 香港科大
- C#和java的对比及总结
1.Java里的AClass.class得到的Class<T>类的对象对应C#的typeof(AClass)得到的Type类型的对象:(但是C#如果要反射创建对象是用Type对象的Asse ...
- php 获取当前在线用户数量
<?php //在线人数统计 $filename='online.txt';//数据文件 $cookiename='VGOTCN_OnLineCount';//cookie名称 $onlinet ...