Add Search Button

Add Search Button

osullivj35osullivj35 Posts: 1Questions: 0Answers: 0
edited June 2009 in General
Hi

Can I add a Search button instead of having the search happening on keystroke as my table is quite large this can be a bit slow

Thanks
Jerry

Replies

  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    Yes indeed! You can build your own using the API: http://datatables.net/api#fnFilter

    You might also be interesting in the excellent fnSetFilteringDelay() plug-in from Zygimantas Berziunas: http://datatables.net/plug-ins#api_fnSetFilteringDelay

    Regards,
    Allan
  • iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1
    Hello,

    I looked at the above links, but I didn't see how to implement this.
    I would also like to have a search function with "OK" and "Reset" buttons, so that the search is not happening on keystroke.

    Another item I would like to be able to provide is a bookmarkable link/url to the search results.

    Could you please post an example?

    Cheers,
    iecwebmast
  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    Hi iecwebmast,

    There is quite a few things there. The basic principle of fnFilter, is that you call it on the table object that you created, as shown in it's code example: http://datatables.net/api#fnFilter . If you attach that to an input element of your own creation (using $(...).keyup( function() { ... }) can you get that to work? From there, its just a couple of steps to get everything you want working.

    Regards,
    Allan
  • iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1
    Hi Alan,

    I'm a newbie so I'm not following you so well. Search OK and Reset buttons seem like something which could be useful for everybody. The on-the-fly search filter can be disconcerting to users. You also cannot bookmark or share the results. Would you mind terribly making an example of how this could be done (buttons OK/Rest plus some kind of get url feature)? I would truly appreciate your help.

    Cheers,
    Laila
  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    edited February 2010
    Hi Laila,

    Have you used events much in javascript? It would be well worth reading the jQuery documentation ( http://api.jquery.com/category/events/ ) and also some of the tutorials that are available on the web ( http://www.learningjquery.com/2008/03/working-with-events-part-1 ).

    I won't write the complete code for you (1. because it's a really good idea to learn this, and 2. because I don't have time - unless you are interested in some consultancy work / a support package - http://datatables.net/forums/comments.php?DiscussionID=1280), but here is an example of how simple it is to add a key event listener for an inpiut box. A click to submit is just a step away from that:
    [code]
    $(input).keyup( function(e) {
    oTable.fnFilter( this.value );
    } );
    [/code]
    Regards,
    Allan
  • BadDaddyBadDaddy Posts: 4Questions: 0Answers: 0
    Has anyone successfully implemented a "Go" and "Reset" button?
    If so, can you please provide an example.
    Would be much appreciated, thanks!
  • RonaldRonald Posts: 5Questions: 0Answers: 0
    i haven't implented a Go button but for reset button i write this :

    in jQuery, i create a span button
    $("#reset").html('');

    after i write the click function on this button with filter value = ''
    $('.reset').live('click', function(){oTable.fnFilter('');});

    and finally put the button after my filter in sDom (with css to adjust)
    "sDom": 'f<"#reset">irt',
This discussion has been closed.