DataTables服务器端模式下的“重置"按钮以显示原始表数据 [英] Reset button in DataTables Server Side mode to show the original table data

查看:67
本文介绍了DataTables服务器端模式下的“重置"按钮以显示原始表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器端模式下设置了DataTables 1.10.15.

I have DataTables 1.10.15 set up in Server Side mode.

使用jquery的keyupchange方法完成各种输入后,将触发为表生成数据的ajax脚本.

The ajax script to produce the data for the table is triggered when various inputs are completed by using jquery's keyup and change methods.

我想实现一个按钮来将表重置为原始状态(首次加载页面,在进行任何搜索/排序之前).

I want to implement a button to reset the table to it's original (first time the page is loaded, before any search/sorting) state.

因此,我实现了这一点,这意味着单击按钮(#resetSearch)时,它将清除所有搜索输入字段,然后重绘该表:

So I implemented this which means when a button (#resetSearch) is clicked it clears all the search input fields and then redraws the table:

$('#resetSearch').click(function(){
    $(':input','#primarySearch')
    .not(':button, :submit, :reset, :hidden')
    .val('')
    .removeAttr('checked')
    .removeAttr('selected');

    myTable.draw();
});

变量myTable是对DataTables的引用:

The variable myTable is a reference to DataTables:

var myTable = $('#myTable').DataTable({ });

问题在于,尽管它清除了我所有的搜索输入,但并没有重置表中的sortorder输入.因此,如果我对第2列进行降序排序,然后按#resetSearch,它将按列2降序给出所有结果-因为那里没有代码将其重置为升至0列.

The problem is that although it clears all my search inputs, it doesn't reset the sort and order inputs which are within the table. Therefore if I did a sort descending on column 2, and then pressed #resetSearch, it will give all the results in descending order by column 2 - because there's no code there to reset that to ascending column 0.

我不知道如何定位sortorder输入,以便可以覆盖它们并使之工作.

I don't understand how to target the sort or order inputs such that I could overwrite them and make this work.

请有人帮忙吗?

推荐答案

数据表已经具有针对您的问题的类/选择器".filter-cancel"的处理程序.

Datatables already has handler for class/selector '.filter-cancel' for your issue.

将按钮或内部具有"filter-cancel"类的链接放置到表中(例如),然后单击它进行测试.默认情况下,它将重新加载您的数据并重置所有过滤器.

Put button or link with class 'filter-cancel' inside to your table (in for example) and test by clicking on it. It will reloads your data by default and resets all filters.

这篇关于DataTables服务器端模式下的“重置"按钮以显示原始表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆