When one value is updated, search and replace all occurrences of previous value with new

When one value is updated, search and replace all occurrences of previous value with new

bfarkasbfarkas Posts: 127Questions: 33Answers: 0

Here’s a new one.
I am thinking of having the end users be able to define three choices for a select field. If they go back in and change these options, I would like to take the old value, search all records for it and replace with the new value on submit of the form when they define the value. Too much?

Answers

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,427
    edited September 18

    Are these changes to the table row data in the client only or do you need to update a database on the server?

    Client side you could use rows().every() with a row-selector as a function to filter the rows that match the old value. Then use row().data() to update the row data with the new value.

    For server side update I would probably use an ajax request that sends the old and new values in the data option to a specific server url (script) to execute a DB query to update the table. For a sql like DB I would do something like update my_table set my_column = "new_value" where my_column = "old_value". In the success function use ajax.reload() to refresh the Datatable.

    Kevin

  • bfarkasbfarkas Posts: 127Questions: 33Answers: 0

    Client side only, no servers for this project.
    How do you still know the old value I guess is my stumbling block here.
    Do I just set a variable with each of the three values anytime the edit form is open so that I can Terence them on close or is there some sort of useful api for that?

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,427

    AFAIK there is nothing that keeps track of the previous value in a select. Using a variable to keep track when the form is open sounds like a good way to go.

    Kevin

  • bfarkasbfarkas Posts: 127Questions: 33Answers: 0

    Thanks, going to give it a shot.

Sign In or Register to comment.