Hi,
Is there any way to override the existing column sorting to restrict the main parent row and sort all child rows in igx-tree-grid?
In the attached image right now we have three-row groups 1, 2, and 3 and if I have to sort by Product Name is it possible to sort only the nested rows i.e., 301, 302, 303, 304, and 305 in ascending or descending in each of the 1, 2, and 3 groups and exclude the parent rows 1, 2, and 3 from sorting.
Thanks,
Mani
Hello,
Thank you for posting in our community.
Any IgxColumnComponent or ISortingExpression can use a custom implementation of the ISortingStrategy as a substitute algorithm. What I can suggest is to create your own custom sortingStrategy and to sort only the rows that are not on level 0:
export class MyTreeGridComponent {
...
@ViewChild('column') public column: IgxColumnComponent;
public ngAfterViewInit() {
this.column.sortStrategy = new customSortingStrategy()
}
class customSortingStrategy implements ISortingStrategy {
public sort(data: any[],
fieldName: string,
dir: SortingDirection,
ignoreCase: boolean,
valueResolver: (obj: any, key: string, isDate?: boolean) => any,
isDate?: boolean) {
const isRootRow = data[0].level === 0;
return this.arraySort(data, cmpFunc, isRootRow);
protected arraySort(data: any[], cmpFunc, isRootRow: boolean): any[] {
if (isRootRow) {
return data;
return data.sort(cmpFunc);
I created a sample illustrating my suggestion, which can be found here. Please test it on your side and let me know whether you find it helpful.
Please let me know if you have any further questions or concerns.
Regards, Viktor Kombov Entry Level Software Developer Infragistics, Inc.