3

I use the excellent plugin "footable" to order and filter my tables.

But in some cases, my page must be initialized with a certain filter. For example, my URL is:

myurl/mypage/19

On the server side I get the '19' and send it to the view. Into the view I put this value into an input field.

How to filter this table with this input value just after the page is loaded?

I tried:

$('table').footable();
$('table').trigger('footable_redraw');

and

$('table').footable();
$('table').trigger('footable_initialize');

Without success.

Update

I specify that the filter works. It's just that the filter does not initialize when I put something in the field during the load of the page.

The JS code:

$(document).ready( function() {

    $('table').footable();
    $('table').trigger('footable_initialize');
})

The HTML code:

<input class="form-control" id="filter" type="text" placeholder="Rechercher ..." value="{{ $libelle_classe }}">

<table class="table footable table-hover table-bordered"  data-filter="#filter">

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Dom
  • 2,984
  • 3
  • 34
  • 64

1 Answers1

2

A possible solution is trigger the filter event manually, using the input value:

$(document).ready( function() {
    $('table').trigger('footable_filter', {
        filter: $("#filter").val()
   });
});

I hope this helps!

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
  • 1
    Yes it works fine with your solution. I did not know we can filter like that. I love "footable". Merci. – Dom Feb 16 '16 at 14:08
  • The filter event in `footable.filter.js` is called when keyup event of input is fired. This does not happens when input value is assigned directly. I like "footable" too, is an awesome plugin! – Allan Pereira Feb 16 '16 at 14:33