首页 文章

数据表搜索过滤器

提问于
浏览
0

我有这样的数据表

var table = $("#tbl_multipoinfo");
        var filter = $('.form-filterpo');
        var target = table.attr('data-table');
        $("#pideldate").datepicker({
            dateFormat: 'yy-mm-dd'                                    
        });

        var oTable = table.on( 'processing.dt', function ( e, settings, processing ) {
                if (processing) {
                    $(this).find('tbody').addClass('load1 csspinner');
                } else{
                    $(this).find('tbody').removeClass('load1 csspinner');
                };
            } ).DataTable({
                "ajax": host+'datatable/'+target,
                "bServerSide": true,
                "order": [[ 1, "desc" ]],
                "bFilter" : true,
                "scrollY":        "200px",
                "scrollCollapse": true,
                "paging":         false,
                "paging":         false,
                "ordering": false
            });

但我的问题是我被困在seacrh过滤器(功能DATATABLE),即使我正在尝试输入任何仍然无法工作的东西,我尝试使用这些代码

$('.dataTables_filter input').unbind().keyup(function(e) {
             var value = $(this).val();
             if (value.length>0) {
                oTable.search(value).draw();
            } else {     
                //optional, reset the search if the phrase 
                //is less then 3 characters long
                oTable.search('').draw();
            } 
        });

但它不会让我过滤,仍然是相同的结果 . 我可能会遗漏一些东西,所以有人能帮我解决这些问题吗?

1 回答

  • 0

    我找到了解决方案,我在Datatable上更改了我的代码

    "bServerSide": true,
    

    我删除了它,我把这样的另一个输入

    <form class="form-filterpo" role="form">
                        <div class="row">
                            <div class="col-md-3 pull-right" style="padding-bottom:5px;">
                                <label>PO : </label>
                                <input id="fPono" class="form-control input-sm" type="text">
                            </div>
                        </div>
                    </form>
    

    并在jquery上添加这些(在jquery我的表中相同)

    $('#tbl_multipoinfo_filter').remove();
    
            filter.find('#fPono').keyup(function(){
                var fPono = $(this).val();
                oTable.columns(1).search(fPono).draw();
            });
    

    它完美地运作 .

    注意:如果你做服务器端尝试把查询而不是在哪里,对于我的情况我不使用查询导致我的查询而不是临时需要检查列表在每一行 .

相关问题