jQuery DataTables and Columnfilterwidget Reset all filters button

后端 未结 1 1044
失恋的感觉
失恋的感觉 2021-01-26 05:32

I am new to Javascript.So my question is a little silly.

I was looking for Reset all filter button for Columnfilterwidget and found this code.

$.fn.dataT         


        
1条回答
  •  再見小時候
    2021-01-26 06:13

    You need to add the preventDefault() to your original button click listener, you've actually added another one.

    Modify your code so it looks like this:

    $(document).ready(function(){
       $("button").click(function(e){
          e.preventDefault();
          console.log("afterbutton");
          ...
    

    It also looks like you've included the function definition inside your button click code.

    It needs to look something more like this:

    $(document).ready(function(){
    // function definition
     $.fn.dataTableExt.oApi.fnResetAllFilters = function (oSettings, bDraw/default true/) {
        for(iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
        oSettings.aoPreSearchCols[ iCol ].sSearch = '';
        }
        $('.filter-term').remove();
        oSettings.oPreviousSearch.sSearch = '';
        if(typeof bDraw === 'undefined') bDraw = true;
        if(bDraw) this.fnDraw();
        }
    });
    
    // button click event
    $("button").click(function(e){
            e.preventDefault();
            // 'myDataTable' is the name you gave the datatable at initialisation - oTable or similar
            myDataTable.fnResetAllFilters();
      });
    });
    

    0 讨论(0)
提交回复
热议问题