How to update _other_ rows after edit?

How to update _other_ rows after edit?

co-operateco-operate Posts: 2Questions: 1Answers: 0

I'm using DataTables with Editor to edit a MySQL table. I need to implement a custom logic when editing the "single" column. Here's my table structure and initial data:

CREATE TABLE tasks (
    id INT PRIMARY KEY,
    `group` VARCHAR(50),
    sum INT,
    single INT,
    result VARCHAR(10)
);

INSERT INTO tasks VALUES
(1, 'task_a', 100, 5, 'fail'),
(2, 'task_a', 100, 94, 'fail'),
(3, 'task_a', 100, 2, 'fail'),
(4, 'task_b', 20, 20, 'success'),
(5, 'task_b', 20, 0, 'success');

I've set up DataTables Editor to edit only the single column, and now I want to implement the following logic when this single column is edited:
When a value for group task_a is changed, collect other all rows where group is also task_a and calculate the sum of all single values.
If the calculated sum equals the sum value of the edited row, then update all rows where group is task_a to result => success.

How can I implement this logic using DataTables Editor? I'm particularly unsure about:

  1. How to update multiple rows based on this calculation.
  2. How to refresh the DataTable to show the updated results.

Answers

Sign In or Register to comment.