datatable 自定义筛选按钮的解决方案

在这里插入图片描述

HTML按钮

<!--操作按钮-->
<div class="btn-group">
    <button id="progress">正常</button>
    <button id="alerted">警告</button>
    <button id="closed">停机</button>
</div>

JS操事件

    $(function () {
        $('#progress').on('click', function () {
            $('.dataTables_filter [type=search]').val("正常运行").keyup();
        });

        $('#alerted').on('click', function () {
            $('.dataTables_filter [type=search]').val("警告").keyup();
        });

        $('#closed').on('click', function () {
            $('.dataTables_filter [type=search]').val("停机").keyup();
        });
    })

JS配置项

  dom: '<"searchBox"lf>tip',//控件位置
                bFilter: true,//过滤
                pagingType: "first_last_numbers",//分页样式
                pageLength: 10,//默认显示条数;
                bPaginate: true,//分页总开关

CSS样式

/*弹出模态框筛选组*/
.btn-group {
    margin-top: 10px;
    float: left;
    margin-left: 10px;
    display: inline-block;
}

#progress {
    width: 80px;
    height: 30px;
    color: #fff;
    outline: none;
    border: 0;
    border-radius: 5px;
    background: #01a016;
    cursor: pointer;
}

#alerted {
    width: 80px;
    height: 30px;
    color: #fff;
    outline: none;
    border: 0;
    border-radius: 5px;
    background: #e60000;
    cursor: pointer;
}

#closed {
    width: 80px;
    height: 30px;
    color: #fff;
    outline: none;
    border: 0;
    border-radius: 5px;
    background: rgba(173, 148, 1, 1);
    cursor: pointer;
}

.searchBox {
    float: right;
    display: inline-block;
    margin-top: -25px;
    margin-right: 10px;
}

.searchBox select {
    width: 60px;
    height: 26px;
}

.searchBox input {
    width: 100px;
    height: 26px;
}

#example_filter {
    margin-left: 20px;
}

@lockdata.cn

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漏刻有时

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值