Using an external search box ?

Using an external search box ?

smartnut007smartnut007 Posts: 1Questions: 0Answers: 0
edited August 2011 in General
I want to have a search box outside the datatables table. So, after trying to figure our the datatables api( I am a javascript nube ), I got it working by doing this.

I basically hid the datatables search box and copied the contents of the external search box to the datatables search box.
I am using ajax and server side processing.

[code]
$(function(){
$("#profile_list_filter input").parent().hide();
//The id of my external search box is #search.
$("#search").keyup( function(){
$("#profile_list_filter input").val( $(this).val() );
$("#profile_list_filter input").keyup();
} );
});
[/code]

Is there a better way to do this ? Esp using the datatables apis to be able to
a) add addional parameters to the ajax calls.
b) make datatables reload data based on external event.

Replies

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    You could remove the need to hide the default search box by not including the 'f' option in sDom: http://datatables.net/ref#sDom . Also probably better you use fnFilter to do the filtering: http://datatables.net/api#fnFilter rather than hijacking the DataTables input box :-)

    Allan
This discussion has been closed.