Posted 27 March 2019, 1:49 pm EST
I see why from a technical standpoint that happens (though I still think it’s weird one can’t apply a class to a column, regardless of cell type), but it leaves us with a problem.
Our columns are dynamically created from an array of items, which was setting the column class based on a property of these items. Let’s say, for example, an array of employees, and a color would be set depending on the employees’ department. The rows are various hierarchical data about, for example, data access privileges, keyed by the employee’s id.
We are using the grid in Angular 2, not JS like my fiddle. So because the itemFormatter sets ‘this’ to the grid, the itemFormatter function no longer has access to the component, and thus has no access to the employee array. So the only way we can pull this off is do something like this:
export class EmployeeGridComponent {
@Input() employees: Employee[];
@Input() treeData: any[]
@ViewChild(WjFlexGrid) grid: WjFlexGrid;
ngOnInit() {
// change 'this'
this.grid.itemFormatter = this.itemFormatter.bind(this);
this.employees.forEach(e => this.grid.columns.push({
binding: employee.id,
header: employee.name
width: 80,
// this no longer works
cssClass: employee.department === 'IT' ? 'it-dept' : 'other-dept'
}))
}
itemFormatter: function(panel, r, c, cell) {
const employeeIndex = c - NUM_OF_STATIC_COLUMNS;
const employee = this.employees[employeeIndex];
if (employee.department == 'IT') {
wijmo.toggleClass(cell, 'it-dept', true);
} else {
wijmo.toggleClass(cell, 'other-dept', true);
}
}
}
It works, but it’s sure a hassle and awfully brittle compared to using cssClass.