Avoid adding color formatting to final row of a datatable

Hello! In my project I build a datatable with conditional color formatting in one of the columns (price) using a styleInterval. This works perfectly to color my table as I'd like. However the final row of the table is a "Total row" and I would not like to apply the styleInterval to it.

Is there a way to ignore this formatting for the final row? Or override the formatting to set the background color of the total row to white? There is a column in the row that indicates it is the Total row so maybe this can be used as a condition on the formatStyle? I attempted to bind the total row to the datatable after the formatStyle but was unsuccessful. Basically I would just like no coloring on the final row. Please help!

Here is the data table output in the server side

output$myTable <- DT::renderDataTable({DT::datatable(myTableData, rownames = FALSE, 
                options =  list(columnDefs = list(list(className = 'dt-center', targets = 0:10),
                                ordering = FALSE, paging = FALSE, searching = FALSE, info = FALSE)) %>% 
    formatRound(columns=c(4:5,10:11), digits=2) %>% 

    formatStyle(
      columns = 'price',
      backgroundColor = styleInterval(break_points(0,2,num_brks), g2r_clrs),
      fontWeight = 'bold'
    )})

Helper functions to build color gradient

break_points <- function(min, max, num) seq(min, max, (max-min)/num)
green_to_red_func <- colorRampPalette(c("#009933", "#FFFF99", "#FF3333"))
num_brks<-14
g2r_clrs <- green_to_red_func(num_brks+2) #c("#009933", "#FFFF99","#FF3333")

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.