I want to use DataTable in my project. So I downloaded the plugin and I integrated it in my app. I tested it with static data it’s work perfectly, but when I want to display data from my DB, I get this message No data available in table despite the data already displayed.
Sort, search and pagination doesn’t work ! it seems the DataTable loaded before the data received or something like that !
Any one had the same problem ? Did I miss something !
Hey kiko91, have you taken a look at the Tabular package? It’s a really easy way to use data tables in your app and it manages the publication/subscription automatically.
Sure it is. In your tabular table’s definition, for the action column, instead of providing a data key, use tmpl: Meteor.isClient && Template.myTablesActionButtons.
The onRendered event is fired when all the non-reactive elements of the template are ready.
At that time it’s very likely that your subscription will not have received any of the published documents. So your datatable will be referencing an empty (or part-empty) table when it’s instantiated.
I can’t see all your template in that png, but most of it is reactive : anything relying on a helper (like {{#if Template.subscriptionsReady)}}, {{#each clientsLive}}. <td>{{name}}</td> etc.
The easiest action is to make use of that {{#if Template.subscriptionsReady)}} section to instantiate a new template, the onRendered of which executes the $('.dataTables-example').DataTable(); line. It’s not a very clean solution, mainly because that bit of jQuery is operating at the global page level, rather than the template or parent template level, but I think it will work!