简体   繁体   English

如何通过单击“清除”按钮清除筛选器后刷新数据表表

[英]how to refresh a datatables table after clearing the filter by clicking on a “clear” button

I have modified the dataTables filter input into a Jquery Mobile search filter , which also inlcudes a delete button, to clear the input field. 我已将dataTables过滤器输入修改为Jquery Mobile搜索过滤器 ,该过滤器也包含删除按钮,以清除输入字段。

This only works half-way, because when I click delete, the input field clears BUT the tables does not update. 这仅适用于中途,因为当我单击删除时,输入字段将清除,但表不会更新。

So I'm looking for some hints on how to refresh the table when clicking on my custom delete button inside the _fnFeatureHtmlFilter function? 所以,当我点击_fnFeatureHtmlFilter函数中的自定义删除按钮时,我正在寻找一些关于如何刷新表格的提示?

The below code shows how I set up the JQM search. 以下代码显示了我如何设置JQM搜索。 Don't think it's helpful for answering the question though... 不要认为它有助于回答这个问题......

    /* jqm search input */
    sSearchStr = oSettings.oInit.bJQueryMobileUI == true ? '<input placeholder="Filtern" data-type="search" data-theme="'+DataTable.ext.oJQMthemes.wrapperTheme+'" />' : 
         ( (sSearchStr.indexOf('_INPUT_') !== -1) ?
             sSearchStr.replace('_INPUT_', '<input type="text" />') :
                sSearchStr==="" ? '<input type="text" />' : sSearchStr+' <input type="text" />' );
    var nFilter = document.createElement( 'div' );
    /* jqm wrapper classes */
    nFilter.className = oSettings.oInit.bJQueryMobileUI == true ? "ui-block-c "+oSettings.oClasses.sFilter : oSettings.oClasses.sFilter;
    oSettings.oInit.bJQueryMobileUI == true ? $(nFilter).html(sSearchStr) : $(nFilter).html('<label>'+sSearchStr+'</label>');

Thanks for some tips! 谢谢你的一些提示!

Found a solution: 找到了解决方案:

 $('.dataTables_filter .ui-input-clear').live('click', function(e) {    
      jqFilter.val("");
      jqFilter.trigger('keyup.DT');
      });

This binds to the clear button. 这绑定到清除按钮。 So when it's clicked I'm setting the input value to "" manually, because the JQM clear button doesn't seem to really clear the input itself. 因此,当它被点击时,我手动将输入值设置为“”,因为JQM清除按钮似乎并没有真正清除输入本身。

With my cleared input I trigger a keyup on the input. 使用我清除的输入,我会在输入上触发一个键盘。 This will fire the normal dataTables rountine, which will fire the fnFilter function, because now jqFilter.value does not match the previous search term. 这将触发正常的dataTables rountine,它会触发fnFilter函数,因为现在jqFilter.value与之前的搜索词不匹配。 Because jqFilter is empty fnFilter will show the whole table again. 因为jqFilter是空的, fnFilter会再次显示整个表。

Maybe useful for somebody else, too. 对其他人也许有用。

You can programatically clear the filter by asking the DataTables API to search for empty string: 您可以通过要求DataTables API搜索空字符串来以编程方式清除过滤器:

$('#myTable').dataTable().fnFilter('');

or if you already have an object reference: 或者如果您已有对象引用:

oMyTable.fnFilter('');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM