Closed georgianastasov closed 2 weeks ago
The documentation states that:
The grid sortStrategy
is of type IGridSortingStrategy
and the sort
method is as follows:
sort(data: any[], expressions: ISortingExpression[], grid?: GridType): any[]
The column sortStrategy
is of type ISortingStrategy
and the sort
method is as follows:
sort: (
data: any[],
fieldName: string,
dir: SortingDirection,
ignoreCase: boolean,
valueResolver: (obj: any, key: string, isDate?: boolean) => any,
isDate?: boolean,
isTime?: boolean,
grid?: GridType
) => any[];
The DefaultSortingStrategy
implements the ISortingStrategy
and its sort
method requires the same parameters:
sort(data, fieldName, dir, ignoreCase, valueResolver, isDate?, isTime?): any[]
So the DefaultSortingStrategy
cannot be assigned to the grid sortStrategy
since they are of different types and the DefaultSortingStrategy
is intended to be used on a column level not on the grid level.
If we proceed with the Steps to reproduce, the app cannot be run due to a compilation error which basically says the above.
The equivalent of the DefaultSortingStrategy
for the grid is the IgxSorting
class:
public defaultGridSortingStrategy = new IgxSorting();
public defaultColumnSortingStrategy = DefaultSortingStrategy.instance();
<igx-grid [data]="data" [sortStrategy]="defaultGridSortingStrategy">
<igx-column
field="ID"
[sortable]="true"
[sortStrategy]="defaultColumnSortingStrategy"
></igx-column>
</igx-grid>
Description
When using DefaultSortingStrategy with any grid component (igx-grid, igx-tree-grid, igx-hierarchical-grid), an error occurs in the console related to sorting functionality.
Steps to reproduce
Create a grid component (igx-grid, igx-tree-grid, or igx-hierarchical-grid) in your Angular application.
Add the following sorting strategy to your component class:
public defaultSortingStrategy = DefaultSortingStrategy.instance();
Bind the defaultSortingStrategy to the grid's [sortStrategy] property:
<igx-grid #grid [data]="data" [sortStrategy]="defaultSortingStrategy">
Run the application and observe the console for errors.
Result
An error is thrown in the console:
Expected result
The grid should sort data correctly without any errors in the console.