twitter-bootstrap bootstrap-table-filter-control 扩展在 bootstrap-table 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32502307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:08:52  来源:igfitidea点击:

bootstrap-table-filter-control extension doesn't work in bootstrap-table

javascriptjquerytwitter-bootstraptwitter-bootstrap-3bootstrap-table

提问by Matt

I use bootstrap-tableand would like to use table-filter-controlextension. In thisexample you can see how to use this extension. When I want to use this extension for more columns, it doesn't work. In my example filter works only for one column.

我使用bootstrap-table并想使用table-filter-control扩展。在这个例子中,你可以看到如何使用这个扩展。当我想将此扩展用于更多列时,它不起作用。在我的示例中,过滤器仅适用于一列。

jsfiddle

提琴手

html

html

<table ref="mainTable" class="table table-striped table-bordered table-hover" 
       cellSpacing="0" id="mainTable" data-show-toggle="true" 
       data-show-columns="true" data-search="true" data-pagination="true" data-filter-control="true">
    <thead>
        <tr>
            <th data-field="state" data-checkbox="true"></th>
            <th data-field="Customer Name" data-sortable="true" data-filter-control="select">Customer Name</th>
            <th data-field="Location Type" data-sortable="true">Location Type</th>
            <th data-field="Location" data-sortable="true" data-filter-control="select">Location</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td></td>
            <td>Cap Corp</td>
            <td>Main</td>
            <td>Norwalk CT 06851</td>
        </tr>
        <tr>
            <td></td>
            <td>Cap Corp</td>
            <td>Other</td>
            <td>Norwalk CT 06851</td>
        </tr>
        <tr>
            <td></td>
            <td>Tel</td>
            <td>Main</td>
            <td>Slough SL1 4DX</td>
        </tr>
        <tr>
            <td></td>
            <td>Tel</td>
            <td>Other</td>
            <td>London W1B 5HQ</td>
        </tr>
    </tbody>
</table>

采纳答案by aattd

data-filed should have not spaces, try to change

data-filed 应该没有空格,尝试更改

data-field="Customer Name"

to

data-field="CustomerName"

I updated your jsfiddle and filter-control works.

我更新了你的 jsfiddle 和 filter-control 作品。

http://jsfiddle.net/5h595r6g/9/

http://jsfiddle.net/5h595r6g/9/

However it would be great to implement filter options updating to available values, as I described in this post:

但是,正如我在这篇文章中所描述的那样,将过滤器选项更新为可用值会很棒:

bootstrap table filter-control - how to unset unnecessary values from select options

引导表过滤器控制 - 如何从选择选项中取消设置不必要的值

回答by Jeff Bluemel

I actually put select2 boxes in the headers, and then used the params feature to pass the code to the server. I made for a much nicer solution. My code isn't with me but if you are interested in it I can pass a sample along Monday.

我实际上将 select2 框放在标题中,然后使用 params 功能将代码传递给服务器。我提出了一个更好的解决方案。我的代码不在我身边,但如果你对它感兴趣,我可以在星期一传递一个样本。

Edited to add example.

编辑添加示例。

Basic Table

基本表

        <table id='90day'  class='table table-striped' data-filter-control='true'>
            <thead>
                <tr>
                    <th></th>
                    <th><select id='findfield' class='form-control gosearch'><option></option></select></th>
                    <th><select id='findwellname' class='form-control gosearch'><option></option></select></th>
                </tr>
            </thead>
        </table>        

Initialize the select2

初始化select2

        $('#90day').on('post-header.bs.table', function () {
            $('#findfield').select2({
                width: '100%',
                placeholder: 'Field',
                allowClear: true,
                SingleSelection: true,
                ajax: {
                    url: 'selectfield90day.php?active=y',
                    dataType: 'json',
                    //delay: 250,
                    data: function (params) {
                        $('#findfield').empty();
                        var d = new Date();
                        var n = d.getTime();
                        return {
                            q: params.term,
                            n: n
                        };
                    },
                    processResults: function (data) {
                        return { results: data };
                    }
                }
            }); 
            $('#findwellname').select2({
                width: '100%',
                placeholder: 'Name',
                allowClear: true,
                ajax: {
                    url: 'selectwellname90day.php?active=y',
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        $('#findwellname').empty();
                        var d = new Date();
                        var n = d.getTime();
                        return {
                            q: params.term,
                            field: $('#findfield').text(),
                            pad: $('#findpad').text(),
                            n: n
                        };
                    },
                    processResults: function (data) {
                        return {
                            results: data
                        };
                    }
                }
            });

            //refresh on any select2 change
            $('.gosearch').on('select2:close', function(){
                $('#90day').bootstrapTable('refresh');
            }); 
        });

Finally table initialization

最后表初始化

$('#90day').bootstrapTable({
    url: ...,
    columns:[
        ...
    ],
    queryParams: function(params){
        params['field']=$('#findfield').text();
        params['well_name']=$('#findwellname').text();      
        return params;
    }
});