Search code examples
javascriptjquerypromisefootable

How do I continue do things after finish footable initialize?


I use query plugin named fooTable for my data table (http://fooplugins.github.io/FooTable/)

Below is my code to initialize my datatable...

jQuery(function($){
  $('.table').footable({
      "paging": { "size": 15 },
      // "toggleColumn": "last",
      "showToggle": false,
      "columns": $.get('/footable/js/columns.json'),
      "rows": $.get('/footable/js/rows.json')
  })
})

My question is how to do something after it finished initialize?

I try

jQuery(function($){
  $('.table').footable({
      "paging": { "size": 15 },
      // "toggleColumn": "last",
      "showToggle": false,
      "columns": $.get('/footable/js/columns.json'),
      "rows": $.get('/footable/js/rows.json')
  })
  .done(function(){
    alert('do something');
  })
})

But it was not working.


Solution

  • use postinit.ft.table event. See http://fooplugins.github.io/FooTable/docs/jsdocs/FooTable.html#.event:Table%2522postinit.ft.table%2522

    The postinit.ft.table event is raised after any components are initialized but before the table is drawn for the first time. Calling preventDefault on this event will disable the initial drawing of the table.

    Also, postdraw.ft.table is what you may want.

    About how to use it

    I am not very familiar to it. So give it a try. If it doesn't work tell me.

    .when('postinit.ft.table', function(e, ft){
        //ok
    })