Keep textbox value

Keep textbox value

wuwuwuwu Posts: 52Questions: 17Answers: 0

Hi, I have a form which has datatable and a textbox. On jquery I command datatable.ajax.reload() but once the datatable is refresh, the textbox also refresh the value. Is there a way we can keep the value entered in the textbox even after i command datatable.ajax.reload()?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862

    Where is the textbox? Is it in the table?

    Using ajax.reload() is going to refresh all the table rows with the data from the server. Assuming the textbox is in the table you will need to update the source data with changes to the textbox via ajax. This way the value is read from the server when using ajax.reload().

    If the textbox is elsewhere then something else is clearing the textbox as ajax.reload() won't affect anything outside of the table data.

    If you still need help then please post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Kevin,

    The textbox is outside the datatable.
    When I input on the textbox and click save, it will update the datatable when i command the datatable.ajax.reload() but it also remove the value i entered in the textbox. it is something like it refresh the page also and not only the datatable.

    Thanks

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862

    it is something like it refresh the page also and not only the datatable.

    ajax.reload() only refreshes the table data via Ajax. It does not refresh anything outside of Datatables as it doesn't know anything about other HTMl elements. Something else is clearing the textbox.

    For help debugging we will need to see the issue. Please post a link to a test case showing the problem.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Yes. I tried to remove the datatable.ajax.reload() and it does not remove the value in the textbox. When I returned back, it removes the value.

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862

    When I returned back, it removes the value.

    Doesn't sound like a Datatables issue. If you want help debugging then please post a test case.

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Kevin,

    $.ajax({
    type: 'POST'
    url: '../Test/TestCreate',
    data: data
    contentType: ápplication/json'
    success: function (data) {
    table.ajax.reload();
    }
    });

    This is the part of the codes that when button is clicked, it will run this. TestCreate is just updating the table base on the textbox i inputted.
    When successful saving, I call table.ajax.reload() to refresh the value of the datatable. But it also remove the value of the textbox.

  • colincolin Posts: 15,227Questions: 1Answers: 2,593

    If you want to update the table, it would be worth looking at Editor. That is designed for updating the table, and syncing those changes back to a server so they persist.

    Colin

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862
    edited November 2023 Answer ✓

    It's still not clear, with that code snippet, how the testbox would be cleared. My understanding is the textbox is a separate element not part of Datatables. Datatables won't know about this element and won't clear it. There is something else in the code/process that is clearing the textbox.

    However if the textbox is in the table then that suggests the table data isn't updated in the database. Use the browser's network inspector to see the JSON response from the server when using ajax.reload().

    We will need to see a running example of the issue to help debug. If yo can't link to your page please get one of the ajax examples here and build a simple test case replicating the issue.

    Kevin

Sign In or Register to comment.