Search code examples
footable

How to initialize the filter of a table just after the loading of the page


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


Solution

  • 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!