Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 00b0751

Browse files
committed
feat(sort): add default sort field as grid option
- when clearing sorting, the default is to use as sort is "id". This new grid option allows to provide another field id.
1 parent 8d8217e commit 00b0751

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"lodash.isequal": "^4.5.0",
9191
"moment-mini": "^2.22.1",
9292
"rxjs": "^6.3.3",
93-
"slickgrid": "^2.4.18",
93+
"slickgrid": "^2.4.19",
9494
"text-encoding-utf-8": "^1.0.2"
9595
},
9696
"devDependencies": {

src/app/examples/grid-basic.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { Column, GridOption } from './../modules/angular-slickgrid';
2+
import { Column, GridOption, Formatters } from './../modules/angular-slickgrid';
33

44
const NB_ITEMS = 995;
55

@@ -27,8 +27,8 @@ export class GridBasicComponent implements OnInit {
2727
{ id: 'title', name: 'Title', field: 'title', sortable: true },
2828
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true },
2929
{ id: '%', name: '% Complete', field: 'percentComplete', sortable: true },
30-
{ id: 'start', name: 'Start', field: 'start' },
31-
{ id: 'finish', name: 'Finish', field: 'finish' },
30+
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso },
31+
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso },
3232
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', sortable: true }
3333
];
3434
this.gridOptions1 = {
@@ -69,8 +69,8 @@ export class GridBasicComponent implements OnInit {
6969
title: 'Task ' + i,
7070
duration: Math.round(Math.random() * 100) + '',
7171
percentComplete: randomPercent,
72-
start: `${randomMonth}/${randomDay}/${randomYear}`,
73-
finish: `${randomMonth}/${randomDay}/${randomYear}`,
72+
start: new Date(randomYear, randomMonth + 1, randomDay),
73+
finish: new Date(randomYear + 1, randomMonth + 1, randomDay),
7474
effortDriven: (i % 5 === 0)
7575
};
7676
}

src/app/modules/angular-slickgrid/editors/longTextEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class LongTextEditor implements Editor {
7373
}
7474

7575
/** Get the Validator function, can be passed in Editor property or Column Definition */
76-
get validator(): EditorValidator {
77-
return this.columnEditor.validator || this.columnDef.validator;
76+
get validator(): EditorValidator | undefined {
77+
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
7878
}
7979

8080
init(): void {

src/app/modules/angular-slickgrid/global-grid-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
7272
syncGridSelectionWithBackendService: false, // but disable it when using backend services
7373
},
7474
datasetIdPropertyName: 'id',
75+
defaultColumnSortFieldId: 'id',
7576
defaultFilter: Filters.input,
7677
enableFilterTrimWhiteSpace: false, // do we want to trim white spaces on all Filters?
7778
defaultFilterPlaceholder: '&#128269;',

src/app/modules/angular-slickgrid/models/gridOption.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ export interface GridOption {
130130
syncGridSelectionWithBackendService?: boolean;
131131
};
132132

133+
/** Defaults to 'id', what is the default column field id to sort when calling clear sorting */
134+
defaultColumnSortFieldId?: string;
135+
133136
/** Default column width, is set to 80 when null */
134137
defaultColumnWidth?: number;
135138

src/app/modules/angular-slickgrid/services/sort.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export class SortService {
111111
this.onBackendSortChanged(undefined, { grid: this._grid, sortCols: [], clearSortTriggered: true });
112112
} else {
113113
if (this._columnDefinitions && Array.isArray(this._columnDefinitions)) {
114-
this.onLocalSortChanged(this._grid, this._dataView, new Array({ sortAsc: true, sortCol: this._columnDefinitions[0], clearSortTriggered: true }));
114+
const sortColFieldId = this._gridOptions && this._gridOptions.defaultColumnSortFieldId || 'id';
115+
const sortCol = { id: sortColFieldId, field: sortColFieldId } as Column;
116+
this.onLocalSortChanged(this._grid, this._dataView, new Array({ sortAsc: true, sortCol, clearSortTriggered: true }));
115117
}
116118
}
117119
} else if (this._isBackendGrid) {

0 commit comments

Comments
 (0)