【问题标题】:Footable, dropdown filterFootable,下拉过滤器
【发布时间】:2020-06-11 12:20:37
【问题描述】:

我正在遵循创建下拉过滤器的指南,[https://fooplugins.github.io/FooTable/docs/examples/advanced/filter-dropdown.html][1]

我做了一个笨表:


    <div class="container">

  <table id="tabella" class="table is-bordered is-fullwidth" style="margin-top: 16px;">
  <thead>
    <tr>
      <th data-breakpoints="xs">PL</th>
      <th data-type="html">Status</th>
      <th data-breakpoints="xs sm">Total Time</th></tr>
   </thead>
   <tbody>
     <tr>
       <td>1</td>
       <td><a href="#">GAR</a></td>
       <td>20:04:12</td>
     </tr>
     <tr>
       <td>2</td>
       <td><a href="#">AUG1</a></td>
       <td>20:13:35</td>
     </tr>
      <tr>
       <td>3</td>
       <td><a href="#">JAIL</a></td>
       <td>10:17:35</td>
     </tr>
   </tbody>
</table>
</div>

我有以下脚本

$(function() {
  $('.table').footable({
    filtering: {
      enabled: true
    }, 
    components: {
        filtering: FooTable.MyFiltering
    }
  });  
});

 $('.footable').trigger('footable_filter', {filter: "Enable"});
FooTable.MyFiltering = FooTable.Filtering.extend({
    construct: function(instance){
        this._super(instance);
        this.statuses = ['GAR','AUG1'];
        this.def = 'Any Status';
        this.$status = null;
    },
    $create: function(){
        this._super();
        var self = this,
            $form_grp = $('<div/>', {'class': 'form-group'})
                .append($('<label/>', {'class': 'sr-only', text: 'Status'}))
                .prependTo(self.$form);

        self.$status = $('<select/>', { 'class': 'form-control' })
            .on('change', {self: self}, self._onStatusDropdownChanged)
            .append($('<option/>', {text: self.def}))
            .appendTo($form_grp);

        $.each(self.statuses, function(i, status){
            self.$status.append($('<option/>').text(status));
        });
    },
    _onStatusDropdownChanged: function(e){
        var self = e.data.self,
            selected = $(this).val();
        if (selected !== self.def){
            self.addFilter('status', selected, ['status']);
        } else {
            self.removeFilter('status');
        }
        self.filter();
    },
    draw: function(){
        this._super();
        var status = this.find('status');
        if (status instanceof FooTable.Filter){
            this.$status.val(status.query.val());
        } else {
            this.$status.val(this.def);
        }
    }
});


不幸的是,过滤器不起作用,我不明白我错在哪里。感谢那些可以帮助我的人!

这是我的密码笔:https://codepen.io/arfry/pen/OJMNVNV

【问题讨论】:

    标签: html jquery dropdown codepen footable


    【解决方案1】:

    解决了!

    需要在要过滤的列的第th添加data-name

    我的表格的行从:

     <th data-type="html">Status</th>
    

     <th data-type="html" data-name='status'>Status</th>
    

    并且工作正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多