使用Bootstrap Table插件,如何在首次加载时设置搜索字符串? [英] with the Bootstrap Table plugin, how to set a search string on first load?

查看:148
本文介绍了使用Bootstrap Table插件,如何在首次加载时设置搜索字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有Bootstrap Table插件( http://bootstrap-table.wenzhixin.net.cn/documentation/)如何在首次加载表格时设置搜索字符串?

With the Bootstrap Table plugin (http://bootstrap-table.wenzhixin.net.cn/documentation/) how to set a search string when the table is loaded for the first time?

仅存在一个数据搜索"属性以启用搜索输入,但这不会使它价值高昂.

Exists only a "data-search" attribute to enable the search input, but this doesn't valorize it.

我正在寻找数据搜索文本"属性,但没有找到.

I looked for a "data-search-text" attribute but I've not found it.

推荐答案

我也需要这样的行为.我的初次尝试是使用bootstrapTable('resetSearch', 'my-query')并设置一个固定的超时时间.可悲的是,这产生了两个请求(如果第一个查询到达客户端,则会产生额外的重排),因此它不是最优的.

I needed such a behavior too. My first attempts were to use bootstrapTable('resetSearch', 'my-query') with a fixed timeout; sadly this was yielding two requests (and additional reflows if the first query made it to the client) so it was sub-optimal.

一段时间后,我发现可以明智地修改查询参数(即仅针对第一个请求)可以实现该目标:

After a while I found that the goal can be achieved modifying query params wisely (i.e. for the first request only):

var start_query = '20';

$('#table').bootstrapTable({
     queryParams: function(params){
        if(start_query){
            $('.bootstrap-table').find('.search input').val(start_query)
            params['search'] = start_query
            start_query = null
        }
        return params
    }
});

有趣的是,$input.val()调用不会触发任何其他回调,因此上面的代码仅使用一个查询/请求.

Interestingly the $input.val() call does not fire any additional callbacks so the code above uses only one query/request.

请在此处查看有效的演示: http://jsfiddle.net/e3nk137y/15364/

Please see a working demo here: http://jsfiddle.net/e3nk137y/15364/

实现这种行为的首选方法可能应该使用searchText选项;可悲的是,它还发出了两个请求.我在引导表存储库中创建了一个问题.

The preferred way to do implement such behavior probably should use searchText option; sadly it also issues two requests. I created an issue in bootstrap-table repo.

针对searchText的两次请求行为的补丁已已合并进入Bootstrap Table插件的开发分支,并且应该是下一发行版的一部分.

Edit 2: A patch for two-request behaviour of searchText has been merged into the development branch of the Bootstrap Table plugin and should be a part of the next release.

这篇关于使用Bootstrap Table插件,如何在首次加载时设置搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆