Change Cell Based on Another Cell using Render Inline Editor
Change Cell Based on Another Cell using Render Inline Editor
aungkohein
Posts: 38Questions: 5Answers: 0
Hi @allan!
I would like to change a cell value based on another cell's database record. E.g if cell A is XYZ in database, cell B will show red text ("Open"). How do I point to cell A using render?
I'm using Inline Editor.
row[0] - cell A
row[1] - cell B
//Status -17
{ "width": 45, "targets": 17,
render: function (data, type, full, meta) {
if (data == "Open") {
return "<div class='text-wrap width-45 red-background smalltxt'>" + data + "</div>";
}
This discussion has been closed.
Replies
Hi @aungkohein ,
You could use
createdRow
as in this example. With that, the change is only made when the row is created, so the criteria is changed, the row won't be updated to reflect that. If the data is likely to change, you could userowCallback
ordrawCallback
,Cheers,
Colin
Hi @colin,
This is great! Thank you very much! I used createdRow() and rowCallback() to change cell contents and colors based on another cell.
Just 1 minor issue, addClass only working for standard class name like red, blue, etc. But if I use custom css from my style.css for example, addClass('orange-text'), it does not show orange text.
The style.css is well linked on my index page. So I believe the Datatables is pointing to another css file?
Hi @colin,
I realized that these methods does not change the actual value of another cell into the database. It's just a css overwrite on display.
Is it possible to develop into changing the value of another cell and write into database?
It might be helpful to review the server side events such as preEdit and postEdit.
Using those, you'd update the data on the server side and your table would refresh with the update.
https://editor.datatables.net/manual/php/events
Hi @aungkohein ,
Yep, as @Loren Maxwell , if you want to change a value, it's best to use events. You can either use server side as suggested already, or client-side with
preSubmit
,Cheers,
Colin