My grid has classes that are conditionally added depending on the column type of the value and I currently have a separate file just to house class rules, which looks something like this:
export const deltaClassRules = {
'ag-right-aligned-cell col-delta col-delta-negative': params => params.value < 0,
'ag-right-aligned-cell col-delta col-delta-positive': params => params.value > 0,
'ag-right-aligned-cell col-delta col-readonly': params => params.value === 0 || isNaN(params.value)
}
export const readonlyClassRules = {
'ag-right-aligned-cell col-readonly': params => params.colDef.type.includes('rightAlignedContent'),
'col-readonly': params => !params.colDef.type.includes('rightAlignedContent')
}
As you can imagine, when I have to manage conditionals like this, it quickly becomes very messy. Say, for example, I want to be able to add a background to certain columns with the class blue-cell
, but these columns can also have classes to align text to the center align-center
and other classes that are generated based on their value.
So, I’m wondering what is the most efficient way to manage this?