Change Cell Based on Another Cell using Render Inline Editor

Change Cell Based on Another Cell using Render Inline Editor

aungkoheinaungkohein Posts: 38Questions: 5Answers: 0
edited January 2019 in Free community support

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>";
                    }

Replies

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    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 use rowCallback or drawCallback,

    Cheers,

    Colin

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0

    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?

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0

    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?

  • Loren MaxwellLoren Maxwell Posts: 387Questions: 94Answers: 10

    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

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    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

This discussion has been closed.