Reset on Min / Max Range Filters

Reset on Min / Max Range Filters

Hutchy68Hutchy68 Posts: 6Questions: 0Answers: 0
edited April 2012 in General
I have searched and there seems to be no clear cut example of how to reset range filters on Min and Max. I can clear the Global search just fine, but am at a loss as to how to clear the min and max on a range filter. I tried to go at it as a custom filter with a tie to an element name, no joy. Are there any live examples. There are no live examples of how to clear filters, custom or not. It would be nice to have an example of one in action.

Thanks
Tom

Replies

  • Hutchy68Hutchy68 Posts: 6Questions: 0Answers: 0
    edited April 2012
    I half figured it out. Clear the inputs, then envoke the fnFilterClear. Using:

    [code]
    $("input:button").click(function(e) { $('#minBorn').val('');
    $('#maxBorn').val('');
    $('#minDeath').val('');
    $('#maxDeath').val('');
    $('#lineage_order').val('');

    var oTable = $('#phillips').dataTable();
    oTable.fnFilterClear();
    });
    [/code]

    The only issue I have is refreshing the tfoot column fields onblur values. The text input fields are cleared, but the onblur filled fields remain blank until I click into them, then click out. Anyone know how to call them again so the onblur values show?

    Thanks
    Tom
  • Hutchy68Hutchy68 Posts: 6Questions: 0Answers: 0
    edited April 2012
    Better way to code the tfoot and a solution to clearing tfoot.

    The current example code for tfoot input:
    [code]
    $("tfoot input").keyup( function () {
    /* Filter on the column (the index) of this element */
    oTable.fnFilter( this.value, $("tfoot input").index(this) );
    } );

    /*
    * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
    * the footer
    */
    $("tfoot input").each( function (i) {
    asInitVals[i] = this.value;
    } );

    $("tfoot input").focus( function () {
    if ( this.className == "search_init" )
    {
    this.className = "";
    this.value = "";
    }
    } );

    $("tfoot input").blur( function (i) {
    if ( this.value == "" )
    {
    this.className = "search_init";
    this.value = asInitVals[$("tfoot input").index(this)];
    }
    } );
    [/code]

    Pointed out by Glenn on a coding forum the above code could be chained and the array dropped. Just use defaultValue and rely on the value in the input tag:

    [code]
    $("tfoot input")
    .keyup( function () {
    /* Filter on the column (the index) of this element */
    oTable.fnFilter( this.value, $("tfoot input").index(this) );
    })
    .focus( function () {
    if ( this.className == "search_init" )
    {
    this.className = "";
    this.value = "";
    }
    })
    .blur( function (i) {
    if ( this.value == "" )
    {
    this.className = "search_init";
    this.value = this.defaultValue;
    }
    });
    [/code]

    This above code takes care of everything, including loosing the array values and relying on defaultValve. I think I read in another forum post you could also use title.

    It makes it easy to clear all the tfoot fields with one clickable button, which will then trigger the blur on the tfoot inputs again using:

    [code]
    $("input:button").click(function(e) {
    $("tfoot input").val('').trigger('blur');
    var oTable = $('#yourtablename').dataTable();
    oTable.fnFilterClear();
    });
    [/code]

    You still need to point at fnFilterClear() to remove the table's filter. You can add in the value clears to other input fields too, which is what I was doing with my very first post in this thread, clearing the range filters. Also, Just make sure you have the footer defined in your table.

    [code]









    [/code]

    Hope this helps someone. I have started using it and it work great. I'm sure you can adapt it for clearing individual tfoot field using the field name and reset it invidividually.

    Tom
This discussion has been closed.