Setting input value of search field (per column)

Setting input value of search field (per column)

mattrose85mattrose85 Posts: 1Questions: 1Answers: 0

Apologies if this is simple, but I've been stuck on this for some time and it's making my head hurt. I have a need to persist the search values of columns between tabs and screens. This is working when tabs are changed, but when the user changes screens and returns, the search field value (per column of data table) are lost, although the search value is reloaded. This is expected, as I know it's not built in to persist save values between screens. I have a function built that queries the data tables persistence for a column to get the value being loaded, however I just can't work out the jquery required to actually set the value. I have the index of the column and the value that should be there in the search input field, but I'm just not able to work out the jquery to set the value.
Please, if someone is able to tell me how to set the search field with a value using a given index using jquery it'd be very much appreciated.

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    I just can't work out the jquery required to actually set the value.

    jQuery().val() to set the value of an input element.

    I'd need to see some code, or even better a live example on StackBltiz or similar to be able to offer much more help than that.

    Allan

  • kthorngrenkthorngren Posts: 21,444Questions: 26Answers: 4,974

    Sounds like you have stateSave enabled and want to restore the search inputs with column().search() values. There are lots of threads asking this. Maybe one of the solutions in this thread will help. If you still need help please post a link to the test case Allan asked for so we can offer more specific suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

Sign In or Register to comment.