DataTable search resets text input field values to the defaultValue

DataTable search resets text input field values to the defaultValue

Thomas-98765Thomas-98765 Posts: 2Questions: 1Answers: 0

I use a DataTable that includes some classical text rows and some rows with text input fields. The following exmaple descibes my problem:

1) When the page is loaded the value of each input field in the table is "A" (defaultValue of the input fields).
2) The user types in a certain field the text "B". Now, B is the value in the text field. The form is not submitted and the page is not refreshed.
3) Now, the user uses the DataTable search to look for "XYZ".
4) The search filters the table, everything works fine.

5) However, after searching (no reload) the value of the text input is reset to "A", i.e. it is set back to the defaultValue. The users input "B" is lost as soon as the search is executed. The search resets to the defaultValue "A"

Thank you for your help!
Thomas

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908

    Sounds like you are not using Datatable APIs to update the Datatables data cache. If you are updating the table via jQuery, for example, Datatables doesn't know about the changes. You probably will want to use one of the invalidate() APIs list row().invalidate() or cell().invalidate().

    Kevin

  • colincolin Posts: 15,236Questions: 1Answers: 2,598

    Hi @Thomas-98765 ,

    There's a lot going on in your steps there. If Kevin's suggestion doesn't help, we're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • Thomas-98765Thomas-98765 Posts: 2Questions: 1Answers: 0

    Hi Colin,

    thank you for your reply. I published a demo page that shows the problem:

    http://demo.tm3ship.de/

    • Each rowGroup has a text input field in the grouping row
    • Enter some text in this field
    • Then type any text in the search field
    • Problem: The typed text in the text input field is removed as soon as search starts. The input field is set to the initial value.

    I tried several ways of constructing the rowGroup and the input field. It always end up with this beaviour.

    Thank you for your help.
    Thomas

  • colincolin Posts: 15,236Questions: 1Answers: 2,598

    Hi @Thomas-98765 ,

    Ah, that demo really helps, thanks.

    Unfortunately, that's the way RowGroup works, it won't preserve that text, and can't. The groups are only formed based on the current view of the data - for example, if you order by name, the groups are just a single row, order by office, the groups expand. Because the groups are formed based on the current data being displayed, anything you add to a previous group can't be preserved - they're just transient. Even changing page will lose your inputs, as the groups are reformed on each draw.

    Hope that make sense. You could store those input values, and reinsert them again on each draw, but it would start to get messy.

    Cheers,

    Colin

This discussion has been closed.