您的位置:首页 > Web前端 > BootStrap

BootStrap Table 重写API实现 可对列选择性的搜索

2016-07-07 11:08 423 查看


下载地址:http://note.youdao.com/yws/public/redirect/share?id=a470bb9ede4466626edfea2946eb3553&type=false

在 bootStrap table .js修改了如下代码片段:

         if (this.options.search) {
html = [];
html.push(
'<div class="pull-' + this.options.searchAlign + ' search">',

sprintf('<input class="form-control' +
sprintf(' input-%s', this.options.iconSize) +
'" type="text" placeholder="%s">',
this.options.formatSearch()),
'</div>');

this.$toolbar.append(html.join(''));
/**
*根据某列进行搜索
*/
var html_a=[];
html_a.push(
sprintf('<div class="search pull-right" style="margin-right:5px;"> ')+
sprintf('<select id="sel_column" class="form-control"> ')
);

$.each(this.columns, function (i, column) {
if(column.searchable){
html_a.push(sprintf(' <option value='+column.field+' >'+column.title+'</option> '));
}
});

html_a.push(
sprintf('</select>')+
sprintf('</div>')

);

this.$toolbar.append(html_a.join(''));

$('#sel_column').change(function ( event){
var text_t=$('.search input').val();
that.searchText =text_t;
that.scolumnText=$('#sel_column').val();
that.options.searchText = text_t;

that.options.pageNumber = 1;
that.initSearch();
that.updatePagination();
that.trigger('search', text_t);
});
$search = this.$toolbar.find('.search input');
$search.off('keyup drop').on('keyup drop', function (event) {
if (that.options.searchOnEnterKey) {
if (event.keyCode !== 13) {
return;
}
}

clearTimeout(timeoutId); // doesn't matter if it's 0
timeoutId = setTimeout(function () {
that.onSearch(event);
}, that.options.searchTimeOut);
});

if (isIEBrowser()) {
$search.off('mouseup').on('mouseup', function (event) {
clearTimeout(timeoutId); // doesn't matter if it's 0
timeoutId = setTimeout(function () {
that.onSearch(event);
}, that.options.searchTimeOut);
});
}
}
};


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: