How to install datatables with Symfony 4 ?
How to install datatables with Symfony 4 ?
theurtin
Posts: 4Questions: 1Answers: 0
I want to use DataTables in Symfony 4 project with Webpack Encore.
DataTables was installed with (installation instructions) :
yarn add datatables.net-bs4
then i try this (installation instructions) :
var $ = require( 'jquery' );
var dt = require( 'datatables.net' )( window, $ );
$(document).ready( function () {
$('table').dataTable();
} );
but i get this error :
Cannot set property '$' of undefined
I found some help with this error but none work for me.
Any idea ?
This discussion has been closed.
Answers
Hi @theurtin ,
I'm guessing the error is coming from the DataTables initialisation line? I suspect the error is the selector you're using. If the table has an ID of 'table', then line 5 should be:
Cheers,
Colin
Hi !
No the error come from the line 2 :
Hi @theurtin ,
This page here suggests the line should be:
require( 'datatables.net-bs4' )( $ );
Cheers,
Colin
Thanks for helping me but now i get this error :
Sorry - it should be
(window, $)
or simply()
with no parameters. The documentation on the npm package page is wrong I'm afraid.Are you using an AMD loader or CommonJS?
Allan
It seem to be an AMD loader but i used Webpack Encore so i'm not sure.
I try :
and :
i got this error :
I also try :
i got this error :
Are you able to package up your project so I can try it out? I don't see any reason why that wouldn't work I'm afraid. Or can you put together a minimal example that shows the issue?
Thanks,
Allan
Try disable AMD loader in Webpack Encore like this :
This code is also working :
@allan
Any chance to have a manual about how to install with webpack ?
There are no plans for a manual, but the best bet is to look through the forum, there are many threads discussing it, such as this one.
Colin
Oh, I didn't come across this one.
Thank you, I think I can start from here.