jQuery - 数据表 - 重新排序/过滤

发布于 2025-01-10 15:53:49 字数 1407 浏览 0 评论 0原文

我对数据表相当陌生,我想知道你们是否可以帮忙...

目前我创建了 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'
});

基于过滤器我需要做的是使用相同的数据,但更改诸如 orderpageLength 以及可能还有其他一些属性...

我目前执行此操作的方式是销毁表,然后重建它们,我觉得这不是正确的方法来做到这一点,因为它似乎是公平的迟缓。我还发现表被破坏和重建的次数越多,速度就越慢。我目前执行此操作的方式如下:

$('#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文