bootstrap-table-filter实现后台过滤,不使用源码的前端过滤

首先引入所需的css和js

<link href="${ctx}/ftl/common/table/filter-control/bootstrap-table-filter-control.css" rel="stylesheet">
<script type="text/javascript"
            src="${ctx}/ftl/common/table/filter-control/bootstrap-table-filter-control.js"></script>

这里的bootstrap-table-filter不是官网的js我这里对bootstrap-table-filter-control.js进行了修改,取消了filter-control的前台索引,改为回车触发后台索引,所需的css和Js在下方链接

https://gitee.com/xb1995/new-project/attach_files

修改的地方是下面的代码(js文件代码324行)

 //获取输入框内容
                var text = $.trim($(event.currentTarget).val());
                //获取filed
                var $field = $(event.currentTarget).closest('[data-field]').data('field');

                //拼接
                var classes = ".bootstrap-table-filter-control-" + $field;
                $(classes).val(text);

下面的代码是回车查找

function keyDownSearch(e) {
        var allData = {
            startDate: '<#if startDate ??>${startDate}</#if>',
            endDate: '<#if endDate ??>${endDate}</#if>',
            orderno: $(".bootstrap-table-filter-control-orderno").val(),
            specailproductcode: $(".bootstrap-table-filter-control-specailproductcode").val(),
            productclass: $(".bootstrap-table-filter-control-productclass").val(),
            suborderno: $(".bootstrap-table-filter-control-suborderno").val(),
            producttype: $(".bootstrap-table-filter-control-producttype").val(),
            departname: $(".bootstrap-table-filter-control-departname").val(),
            planstarttime: $(".bootstrap-table-filter-control-planstarttime").val(),
            planfinishtime: $(".bootstrap-table-filter-control-planfinishtime").val(),
            finishdate: $(".bootstrap-table-filter-control-finishdate").val(),
            tp_date: $(".bootstrap-table-filter-control-tp_date").val(),
            flag: $(".bootstrap-table-filter-control-flag").val(),
            status: $(".bootstrap-table-filter-control-status").val()
        };
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            $("#tb_departments").bootstrapTable('refresh', {
                query:allData
            });
            console.log("监听成功");
            return false;
        }
        return true;
    }

里面的参数值都是filter-control-input输入框获取的值,.bootstrap-table-filter-control-+你定义的field,这样就获取了input输入框的值。

然后初始化bootstraptable和回车事件

$(function () {
        bootstrapInit();
        document.onkeydown = keyDownSearch;
    });

bootstrap-table初始化网上有很多教程,当然你可以去官网学习

https://examples.bootstrap-table.com/

官网中也有filter-control的用法

最后放一下效果图

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值