Replace Search "keyup" with a Button

Replace Search "keyup" with a Button

martin@sommer.netmartin@sommer.net Posts: 15Questions: 0Answers: 0
edited April 2010 in General
Hi,

I am using server side processing, have tried the fnSetFilteringDelay filter delay, and would simply like to replace the keyup activation with a "Search" button. Too many times users are unexpectedly triggering queries, by doing nothing.

How can this be done?

Thanks,
Martin

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What you need to do is simply unbind the 'keyup' listener that DataTables adds to the input box, and then put a button into the HTML, along with an event listener for it which will call fnFilter() with the input field's value, when it is clicked.

    Regards,
    Allan
  • BadDaddyBadDaddy Posts: 4Questions: 0Answers: 0
    Can you please show an example of this?
  • codecowboycodecowboy Posts: 8Questions: 0Answers: 0
    edited March 2012
    [code]jQuery.fn.dataTableExt.oApi.fnFilterOnButton = function (oSettings) {
    /*
    * Usage: $('#example').dataTable().fnFilterOnButton();
    * Author: Jcodecowboy
    * License: GPL v2 or BSD 3 point style

    */
    var _that = this;

    this.each(function (i) {
    $.fn.dataTableExt.iApiIndex = i;
    var $this = this;
    var anControl = $('input', _that.fnSettings().aanFeatures.f);
    anControl.unbind('keyup');
    var searchButton = $('#id_of_button').bind('click', function(e){
    _that.fnFilter(anControl.val());
    });


    return this;
    });
    return this;
    }

    /* Example call
    $(document).ready(function() {
    $('.dataTable').dataTable().fnFilterOnButton();
    } );
    */[/code]
This discussion has been closed.