getting filter text

getting filter text

valdezrvaldezr Posts: 49Questions: 0Answers: 0
edited May 2009 in General
how can I get the text in the filter input box?

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    $('div.dataTables_filter input').val();

    should do it :-)

    Alternatively, if you want the last search for value you can use oTable.fnSettings().oPreviousSearch.sSearch.]

    Hope that helps,
    Allan
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    You might want to also have a look at this plug-in which demonstrates how you can bind your own event handler to the input search box: http://datatables.net/plug-ins#api_fnSetFilteringDelay
  • atcatc Posts: 14Questions: 0Answers: 0
    edited October 2009
    Hi Allan,

    for some reason, I'm able to get the input value as you described above, but I can't get my code to detect any changes to that text field. I thought perhaps it was because there's no "" defined around the input, but I added that in in the main datatables code and it didn't make a difference.

    For example, I tested this function:
    [code]
    $('input[type="text"]').focus(function() {
    alert('focus!');
    });
    [/code]
    The event fires properly for text fields within another form on the same page, but when I click on the dataTables search input text box, nothing happens.

    Any ideas?

    Thanks much,
    ALison
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Hi Alison,

    Are you adding the event before DataTables is initialised? For example:

    [code]
    $('input[type="text"]').focus(function() {
    alert('focus!');
    });

    $(.whatever).dataTable();
    [/code]
    The text input element that DataTables uses is dynamically generated - so it might be missing your event assignment. Visual Event ( http://www.sprymedia.co.uk/article/Visual+Event ) would confirm if this is the case.

    Regards,
    Allan
This discussion has been closed.