Programmatic manipulation of the search box?

Programmatic manipulation of the search box?

iain_mciain_mc Posts: 15Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
Hullo,

So I'd like to click on a field in the dataTable and have the table filter by that keyword.

Easy to do with a call to fnFilter, but then I have to have another button the user has to click to clear the filter, plus there is no visible indication the table is in a filtered state.

What I'd like to do is take the content of the field, put it into the dataTables search box so that (a) there's a visible cue to the filter, and (b) the user could delete it there to restore the table to its unfiltered state.

Is this possible?

Thanks!

Iain

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Hi Iain,

    DataTables should update the global search input when you do a global search via the fnFilter method (although there is an option to disable that action). I've put an example together here: http://live.datatables.net/oluver/edit#javascript,html

    Allan
  • iain_mciain_mc Posts: 15Questions: 0Answers: 0
    edited February 2013
    Awesome as always, thanks Allan!

    I was using the specific column filter option in fnFilter, hadn't thought of trying the global.

    Cheers, Iain
  • iain_mciain_mc Posts: 15Questions: 0Answers: 0
    Out of interest, is there an easy way to do the same thing and restrict it to a column filter?
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    No, because there are no column filter controls built into DataTables. It doesn't know anything about how you've got your data from wherever to filter on a column (select input, text input, clicking a button, etc), so you need to update whatever control it is that you are using with your own script.

    Allan
This discussion has been closed.