Bootstrap Table 查询实现

实现查询思路:
1.定义一个局左的Toolbar包含 新建、保存和新建的按钮
2.定义一个局右的QueryForm 包含查询条件 和 查询清除按钮
3.定义一个Table

实现效果如下:
这里写图片描述
代码如下

<div class="container-fluid">

    <div>
        <div id="toolbar-btn" class="btn-group pull-left" style="padding-bottom:10px;">
            <button id="btn_add" onclick="createFunction()" type="button" class="btn btn-primary btn-space">
                <span class="fa fa-plus-square" aria-hidden="true" class="btn-icon-space"></span>
                <@spring.message "fnd.new"/>
            </button>
            <button id="btn_save" onclick="saveFunction()" type="button" class="btn btn-success btn-space">
                <span class="fa fa-save" aria-hidden="true" class="btn-icon-space"></span>
                <@spring.message "fnd.save"/>
            </button>
            <button id="btn_delete" onclick="deleteFunction()" type="button" class="btn btn-danger btn-space">
                <span class="fa fa-trash-o" aria-hidden="true" class="btn-icon-space"></span>
                <@spring.message "fnd.delete"/>
            </button>
        </div>

        <div class="pull-right" id="query-form" style="padding-bottom:10px;">
            <input name="lookupType" placeholder='<@spring.message "fnd.lookup_type"/>' type="text"
                   style="float:left;width:150px;margin-right:5px;" v-model="lookupType"
                   class="form-control">
            <div style="float:left;margin-right:5px;">
                <input name="description" placeholder='<@spring.message "fnd.description"/>' type="text"
                       style="float:left;width:150px;margin-right:5px;" v-model="description"
                       class="form-control">
            </div>

            <div class="btn-group">
                <button id="btn_search" onclick="customSearch()" type="button" class="btn btn-primary btn-space">
                    <span class="fa fa-search" aria-hidden="true" class="btn-icon-space"></span>
                    <@spring.message "fnd.query"/>
                </button>
                <button id="btn_reset" onclick="resetSearch()" type="button" class="btn btn-default btn-space">
                    <span class="fa fa-eraser" aria-hidden="true" class="btn-icon-space"></span>
                    <@spring.message "fnd.reset"/>
                </button>
            </div>

        </div>
    </div>


    <table id="table" class="table  table-condensed table-striped"></table>

</div>
  • 查询函数实现
    实现思路:获取查询块中所有的对象,动态存放在查询返回的参数中
    需要注意:
    当查询没有值的之后,不能放入到查询参数中,否则会把数据当做空来查询,从而导致无法查询到数据
function queryParams(params) {
    var param = {};
    $('#query-form').find('[name]').each(function () {
        var value = $(this).val();
        if (value != '') {
            param[$(this).attr('name')] = value;
        }
    });

    param['pageSize'] = params.limit;   //页面大小
    param['pageNumber'] = params.offset;   //页码

    return param;
}

function customSearch(text) {
    $table.bootstrapTable('refresh');//刷新Table,Bootstrap Table 会自动执行重新查询
}
  • 重置函数的实现
    实现思路:循环获取query-form的控件,并把其值置空
function resetSearch() {
    $('#query-form').find('[name]').each(function () {
        $(this).val('');
    });
}
  • 6
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Bootstrap Table 是一个基于Bootstrap框架的可扩展的表格插件,它可以用于展示数据、排序、过滤等。如果你想在Bootstrap Table中进行查询,可以使用它提供的搜索功能。 要在Bootstrap Table实现搜索功能,需要在HTML代码中添加一个搜索框,并使用Bootstrap Table提供的方法来实现搜索。具体步骤如下: 1. 在HTML中添加搜索框 ``` <div class="input-group"> <input type="text" class="form-control" id="searchInput" placeholder="Search..."> <span class="input-group-btn"> <button class="btn btn-default" type="button" id="searchButton"> <span class="glyphicon glyphicon-search"></span> </button> </span> </div> ``` 这段代码中,我们使用了Bootstrap的input-group和glyphicon来创建一个搜索框。搜索框的id为searchInput,搜索按钮的id为searchButton。 2. 在JavaScript中实现搜索功能 ``` $(function() { // 初始化表格 $('#table').bootstrapTable({ // 表格配置 }); // 绑定搜索按钮的点击事件 $('#searchButton').click(function() { // 获取搜索框的内容 var searchText = $('#searchInput').val(); // 使用Bootstrap Table的搜索方法 $('#table').bootstrapTable('search', searchText); }); }); ``` 这段代码中,我们首先初始化了表格,然后在点击搜索按钮时,获取搜索框的内容并使用Bootstrap Tablesearch方法来搜索匹配的数据。注意,这里的tableBootstrap Table表格的id。 以上就是在Bootstrap Table实现查询的方法。你可以根据自己的需求进行定制和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值