Conditional formatting based on changed value

Conditional formatting based on changed value

KimvdLindeKimvdLinde Posts: 30Questions: 8Answers: 0

Okay, I find how to do it in older versions, but how can I change the background color of a specific cell when I change the value with editor?

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29
    edited September 2015

    I change my individual cell classes and styles in the rowCallBack.

    I do it by actually adding and clearing classes. My classes are determined in the .net code, not in javaScript

    if (data[2] .. some condition {
    $("td:eq(2)", row).removeClass(... palette of possible classes..)
    $("td:eq(2)", row).addClass(someClass)
    }
    

    But, you should be able to do it in .css also

    if (data[2] .. some condition {
    $("td:eq(2)", row).css("background-color","#ff00ff")
    }
    

    Now, if you are using zebra stripping, and sorting, you have to handle the hover conditions on the rows to show a nice row that changes color when the user hover's over it. Classes work much better for that purpose, you just need to define each color and it's :hover color when even or odd in a custom .css file

  • KimvdLindeKimvdLinde Posts: 30Questions: 8Answers: 0

    glenderson, that is helpful information, but it does not do the job for me as the values in the cell are also changed without an ajax call that throws the rowCallBack

  • KimvdLindeKimvdLinde Posts: 30Questions: 8Answers: 0
    edited September 2015

    For that reason, I would like to link it to something when the row is updated.

  • KimvdLindeKimvdLinde Posts: 30Questions: 8Answers: 0
    edited September 2015

    Okay, solved it:

                           render: function (val, type, row, meta) {
                            var diff = row.totalCosts-row.ExcludableCosts;
                            if(Math.abs(diff) >0.001) //Not != 0 to deal with minor rounding errors.
                                $('#'+row.DT_RowId).addClass('lightRed');
                            else 
                                $('#'+row.DT_RowId).removeClass('lightRed');
                            return formatAsMoney(diff);
    
This discussion has been closed.