I am trying to add Datatables plugin (datatables.net) facility with my angualar 6 project. I am not sure how should I include the necessary css, js and other required files to my project with npm installer. After selecting my necessary options I am following the NPM Install method with these :
npm install --save datatables.net-bs4
npm install --save datatables.net-buttons-bs4
npm install --save datatables.net-colreorder-bs4
npm install --save datatables.net-responsive-bs4
npm install --save datatables.net-rowgroup-bs4
npm install --save datatables.net-scroller-bs4
After Installing, I am not sure how will I use these in my project. my project is using ngx-bootstrap (https://www.npmjs.com/package/ngx-bootstrap) for styling.
style.scss // where I am only importing my css theme from node_modules
In ngx-bootstrap the styles are component wise, and I am using those easily. So, how can I use datatables features as a component ? In another way, where should I include the css, and required js files to achieve the datatables facilities on a page?
If anyone has done it please let me know, or any suggestions will be appreciated.
Thanks.
By just watching the question and the answer from @dickrichie, I still had an error:
I was missing the two last install steps to make Datatables.net works with Angular 6.
Then follow the message from @dickrichie to edit angular.json and app.module.ts files. Now any table tag where you add "datatable" should work.
-- EDIT
The first part of that answer is with using angular-datatables, but as @fahimuddin asked in fact how to do that without that package, I tried differently.
So no need to install the last two packages, the angular.json looks the same as in @dickrichie answer and in a component I just added before the @Component:
And then use directly jQuery and Datatables in ngOnInit():
It works and nobody's complaining but I'm not sure if it's a good practice? (And as in my case I'm trying to do an Angular-Electron app, it's still not working in Electron, it wasn't working with angular-datatable neither, but that's another problem!)
use angular data tables in Angular 6 angular-datatables
You need to install its dependencies before getting the latest release using NPM:
angular.json
Import the DataTablesModule in app.module.ts
my datatableslibrary.ts
my datatableslibrary.component.html
I got DataTables working by doing the following:
angular.json
app.module.ts
You may have to stop and re-serve to see changes.
You can find a full answer here: https://medium.com/apprendre-le-web-avec-lior/angular-5-and-jquery-datatables-fd1dd2d81d99
Follow the steps and you will be OK
Just add your .css files in styles section and .js files in Scripts section, in angular(-cli).json. I think this would resolve your issues.