How do I Refresh a table

How do I Refresh a table

nisdisnisdis Posts: 1Questions: 1Answers: 0

Hi, I wuld like to know how to refresh a table once a search has been made using .column.search()
Can I clear search using code or clear state of the table ?

Answers

  • allanallan Posts: 63,813Questions: 1Answers: 10,517 Site admin

    Call draw().

    As the documentation for column().search() notes:

    Please be aware that this method sets the search to apply to the table only - it does not actually perform the search. In order to have the search performed and the result shown, use the draw() method

    Allan

  • LauraSuzyLauraSuzy Posts: 12Questions: 4Answers: 1

    I am trying to create a Clear Search button, too, but I am doing something wrong even after reading that documentation and searching the forums for help. Is there an example code page that shows a sample implementation with a Clear Search button that clears the global dataTables search field? If I could look at some working code in a fiddle or something, I could figure out what I am doing wrong. Thanks!

  • allanallan Posts: 63,813Questions: 1Answers: 10,517 Site admin

    All you should need to do is table.search('').draw();.

    Allan

  • LauraSuzyLauraSuzy Posts: 12Questions: 4Answers: 1

    Thanks! I found this example with a wider search: http://jsfiddle.net/4rvmtv7d/

    My problem was that I forgot the single ticks inside the search() function. But I also have 2 other drop-down filters and two range filters, and I have found that I need to use table.columns('').search('').draw() to get the table to reset properly after using the other filters, plus just a table.search('').draw() to reset the table after using the global smart search box. Somehow I think this isn't how it should need to work? I'll have to take a look at my other code to see if I've created some weird dependency, but if you have any insight about this, it would be much appreciated.

    Thanks again for your hard work and great plugin!

  • allanallan Posts: 63,813Questions: 1Answers: 10,517 Site admin

    omehow I think this isn't how it should need to work?

    It sounds correct to me. search() is the global search and columns().search() is the column search. If you are using both and want to clear both, then, yes, you would need to clear both.

    Allan

This discussion has been closed.