update the values based on values in another column
update the values based on values in another column
Khalid Teli
Posts: 251Questions: 71Answers: 0
Hi,
I am using field.multiset()
inside rowCallback function to copy the values of existing column called current_price
into new column called new_price
after a specific date has passed, as shown in the example below.
Everything works fine , except the the code appears to run in a LOOP
rowCallback": function( row, data) {
if (data.date == '2021-11-02') {
editor.edit( table.rows().indexes(),false );
var rows = editor.field( 'new_price' ).multiGet();
$.each( rows, function ( id, val ) {
editor.field( 'new_price' ).multiSet( id, data.current_price );
} );
editor.submit();
}
}
Any help would be appreciated!
Thank you
This discussion has been closed.
Answers
Yep, that would loop.
rowCallback
is called on each draw, as the changing of the data would cause a draw, which would trigger your code.The best bet would be to check the current value before setting the new value, and only change if necessary - that way it would prevent the loop. You would loop around
tables.rows()
first, and only add those row you want to edit into theedit()
,Colin
@colin thanks
tables.rows() didn't work for me so I ended up writing a update query on server side script which worked fine.
Thank you