Help with data tables plugin with Meteor


#1

Hello. Can somebody help with data tables (native) plugin. I am using Package Based Architecture approach- inspired by https://github.com/riebeekn/package-based-architecture.

In my main package (core) I add files like this:

api.addFiles([
        // ** I18 ** //
        'lib/client/plugins/i18next/i18next.min.js',
        // ** DATA TABLES ** //
        'lib/client/plugins/datatables/datatables.min.css',
        'lib/client/plugins/datatables/jquery.dataTables.js',
        'lib/client/plugins/datatables/datatables.js',
        // ** METIS MENU ** //
        'lib/client/plugins/metisMenu/jquery.metisMenu.js',
        'lib/client/plugins/test/test.js',
        //** TOASTR NOTIFICATION **/
        'lib/client/plugins/toastr/toastr.min.css',
        'lib/client/plugins/toastr/toastr.min.js'
    ], 'client');

But when I want use data tables in another package (like Users, Leads etc) I get DataTable is undefined

$('.dataTables-users').DataTable();

Thank’s beforehand.


#2

Hi there,

I really recon you to have a look at aldeed’s tabular package, which does all the work for you and works really well. Here you go - have fun with it :slight_smile: https://github.com/aldeed/meteor-tabular


#3

Thank you! But if I want another JS (jquery) plugin… what I need to do to use it in other packages? I need import files of similar?


#4

Also note, that the package-based structure is NOT recommended anymore… it was something we liked to do in the good old days of meteor. The way to do it today are ES2015 modules… check out this link here, where it is explained very well https://guide.meteor.com/structure.html.

The way to manually include datatables today (I still recon you to use aldeed:tabular) would be to do an meteor npm install datatables-package (https://datatables.net/download/npm) and then in your onRendered() you should be able to attach it to the dom


#5

Note that aldeed:meteor-tabular package does use DataTables jQuery plugin internally and you can use all of its configuration options.