'jQuery - Datatables - Re-sorting / Filtering
I'm fairly new to dataTables and I was wondering if you guys could help...
At the moment I create 4 dataTables as follows:
/* Create Datatables for all Positions // DEFAULT */
$('#fplway-player-list-gk').dataTable( {
order: [[ 5, "desc" ]],
pageLength: 5,
searching: true,
lengthChange: false,
info: false,
dom: 'rtip',
});
$('#fplway-player-list-def').dataTable( {
order: [[ 5, "desc" ]],
pageLength: 8,
searching: true,
lengthChange: false,
info: false,
dom: 'rtip'
});
$('#fplway-player-list-mid').dataTable( {
order: [[ 5, "desc" ]],
pageLength: 14,
searching: true,
lengthChange: false,
info: false,
dom: 'rtip'
});
$('#fplway-player-list-fwd').dataTable( {
order: [[ 5, "desc" ]],
pageLength: 3,
searching: true,
lengthChange: false,
info: false,
dom: 'rtip'
});
What I need to do based on filters is to use the same data but change things like the order, pageLength and maybe a few other attributes...
The way in which I am doing it at the moment is destroying the tables and then rebuilding them which I feel isn't the correct way to do this as it seems to be fairly sluggish. I'm also finding that the more times the tables are destroyed and rebuilt, the slower and slower it becomes. The way I am currently doing this is as follows:
$('#fplway-player-list-gk').DataTable().destroy();
$('#fplway-player-list-def').DataTable().destroy();
$('#fplway-player-list-mid').DataTable().destroy();
$('#fplway-player-list-fwd').DataTable().destroy();
Then I'm running the same code as the initial code above to re-create them with the parameters I need.
Am I doing this incorrectly, or is there a better way to do it?
Just to add, the data is always the same which is around 700 records, essentially all I need to do is update attributes of each dataTable based on filtering...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
