New to Kendo UI for Angular? Start a free 30-day trial
Change Grid Styling When Sorting is Applied
Environment
Product | Progress® Kendo UI for Angular Grid |
Description
How can I change the styles of the Kendo UI for Angular Grid columns and headers when sorting is applied?
Solution
To change the styles of the active Grid columns when sorting is applied:
-
Use the
sortChange
event of the Grid to update theSortDescriptor
.html<kendo-grid> ... (sortChange)="onSortChange($event)" ... </kendo-grid>
typescriptpublic onSortChange(sortDesc: SortDescriptor[]): void { this.sortDescriptors = sortDesc; }
-
Use the
class
andheaderClass
properties of theColumnComponent
to conditionally apply a custom class if the columns field is present in theSortDescriptor
.html<kendo-grid-column field="ProductName" title="Product Name" [headerClass]="{'is-col-sorted': isColumnSorted('ProductName')}" [class]="{'is-col-sorted': isColumnSorted('ProductName')}"> </kendo-grid-column>
typescriptpublic isColumnSorted(colField: string): boolean { return this.sortDescriptors.some((col) => col.dir && col.field === colField); }
-
Use the custom class to apply the desired styles to the sorted columns.
css.is-col-sorted { background-color: #FBEAEB!important; color: #2F3C7E; }
The following example demonstrates the suggested approach.
Change Theme
Theme
Loading ...