jQuery - 数据表 - 重新排序/过滤
我对数据表相当陌生,我想知道你们是否可以帮忙...
目前我创建了 4 个数据表,如下所示:
/* 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'
});
基于过滤器我需要做的是使用相同的数据,但更改诸如 order
、pageLength
以及可能还有其他一些属性...
我目前执行此操作的方式是销毁表,然后重建它们,我觉得这不是正确的方法来做到这一点,因为它似乎是公平的迟缓。我还发现表被破坏和重建的次数越多,速度就越慢。我目前执行此操作的方式如下:
$('#fplway-player-list-gk').DataTable().destroy();
$('#fplway-player-list-def').DataTable().destroy();
$('#fplway-player-list-mid').DataTable().destroy();
$('#fplway-player-list-fwd').DataTable().destroy();
然后我运行与上面的初始代码相同的代码,以使用我需要的参数重新创建它们。
我这样做是否错误,或者有更好的方法吗?
只是补充一下,数据总是相同的,大约有 700 条记录,基本上我需要做的就是根据过滤更新每个数据表的属性......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论