I am following the guidelines for creating a dropdown filter, [https://fooplugins.github.io/FooTable/docs/examples/advanced/filter-dropdown.html][1]
I made a stupid table:
<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>
and i have the following script
$(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);
}
}
});
Unfortunately the filter doesn't work and I don't understand where I'm wrong. Thanks to those who can help me!
This is my codepen: https://codepen.io/arfry/pen/OJMNVNV