The 'cellClass' column def option shouldn't apply to the header cell
I noticed there there are 2 different ColumnDefs Options. From the API docs:
cellClass"appends a css class for the column cells"headerClass"appends a css class for the column header"
Based on this, I would expect the cellClass to only apply to the body rows, not the header row. Because if I wanted to add a CSS class to the column in the header row, I'd just set it via the headerClass option. But what's happening (in the 2.0.8 branch at least) is that the cellClass is being tacked on to every cell's template that calls colIndex():
self.colIndex = function () {
var classes = self.pinned ? "pinned " : "";
classes += "col" + self.index + " colt" + self.index;
if (self.cellClass) {
// *** adds the cellClass to the list of CSS classes, even for the header! ***
classes += " " + self.cellClass;
}
return classes;
};
This prevents me from applying a CSS class to just the cells in the body of the grid, and not in the header. Is this intentional, or a bug?
It's a bit intentional, as header cells are still technically cells.
If you want to directly target only body cells then I think you can use a more specific CSS rule: .ngCanvas .ngCell.yourClassName
Thanks for the clarification. My situation is that I have a grid containing several columns of numbers, and I'm trying to right-align the contents of the numeric cells (like in MS Excel). Since I'm using Bootstrap, I thought that just tacking on cellClass: 'text-right' to the columnDefs would do the trick, but it causes the column headers to be right-aligned as well, which looks strange.
As you suggest, I could create a new CSS class to use for the cellClass property, and use the .ngCanvas .ngCell.myNewClass CSS selector to apply the text-align: right change. However, I decided a better approach was to remove all CSS formatting from the columnDefs, and apply it directly from CSS to the columns I'm interested in:
/* by default all cell values are right-aligned */
.myGrid .ngCell {
text-align: right;
}
/* but the first column contains string values, so leave it left-aligned */
.myGrid .ngCell .col0 {
text-align: left;
}
Steve,
Great, glad you found a solution. I'm not sure if column reordering affects the index (i.e. shifting .col2 to the left makes it become .co1). It shouldn't but it may, just something to keep in mind.
On Wed, Apr 2, 2014 at 11:05 PM, Steve Kingsland [email protected]:
Closed #1089 https://github.com/angular-ui/ng-grid/issues/1089.
Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ng-grid/issues/1089 .