search field ignore manually fired change and keypress events, why?

search field ignore manually fired change and keypress events, why?

mickeyrenmickeyren Posts: 3Questions: 0Answers: 0
edited October 2013 in General
I'm trying to programmatically enter the search text like so:

$('.dataTables_filter input').val('Singapore').trigger('change')
$('.dataTables_filter input').val('Singapore').trigger($.Event("keypress", { keyCode: 15 }))

But this doesn't trigger the search filter at all on datatable - why is that if i manually type in on the search field it works, what is the difference?

i need to filter the rows through a set of buttons and the easiest way for me to do this is to programmatically enter a search text on the search field.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Because the search field in DataTables doesn't listen for either of those events. it watches for keyup. Fire that and it will work.

    Allan
  • mickeyrenmickeyren Posts: 3Questions: 0Answers: 0
    oooh how could i not try that - thanks thanks so much!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This little tool is useful for seeing what events are applied: http://sprymedia.co.uk/article/Visual+Event+2 :-)

    Allan
This discussion has been closed.