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

Commit 16b7f3e

Browse files
authored
Merge pull request #224 from ghiscoding/bugfix/query-field-precendence
fix(queryField): queryFieldFilter and queryFieldSorter have precedence
2 parents add5287 + 5e2d300 commit 16b7f3e

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ export class HeaderMenuExtension implements Extension {
277277
const updatedSortColumns: ColumnSort[] = sortedColsWithoutCurrent.map((col) => {
278278
return {
279279
columnId: col && col.sortCol && col.sortCol.id,
280-
sortAsc: col && col.sortAsc
280+
sortAsc: col && col.sortAsc,
281+
sortCol: col && col.sortCol,
281282
};
282283
});
283284
this.sharedService.grid.setSortColumns(updatedSortColumns); // add sort icon in UI
@@ -335,7 +336,8 @@ export class HeaderMenuExtension implements Extension {
335336
const newSortColumns: ColumnSort[] = sortedColsWithoutCurrent.map((col) => {
336337
return {
337338
columnId: col && col.sortCol && col.sortCol.id,
338-
sortAsc: col && col.sortAsc
339+
sortAsc: col && col.sortAsc,
340+
sortCol: col && col.sortCol,
339341
};
340342
});
341343
this.sharedService.grid.setSortColumns(newSortColumns); // add sort icon in UI

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,22 @@ export interface Column {
153153
/** The previous column width in pixels (number only) */
154154
previousWidth?: number;
155155

156-
/** Useful when you want to display a certain field to the UI, but you want to use another field to query for Filtering/Sorting. */
156+
/**
157+
* Useful when you want to display a certain field to the UI, but you want to use another field to query when Filtering/Sorting.
158+
* Please note that it has higher precendence over the "field" property.
159+
*/
157160
queryField?: string;
158161

159-
/** Similar to "queryField" but only used with Filtering. Useful when you want to display a certain field to the UI, but you want to use another field to query for Filtering. */
162+
/**
163+
* Similar to "queryField" but only used when Filtering (please note that it has higher precendence over "queryField").
164+
* Useful when you want to display a certain field to the UI, but you want to use another field to query for Filtering.
165+
*/
160166
queryFieldFilter?: string;
161167

162-
/** Similar to "queryField" but only used with Sorting. Useful when you want to display a certain field to the UI, but you want to use another field to query for Sorting. */
168+
/**
169+
* Similar to "queryField" but only used when Sorting (please note that it has higher precendence over "queryField").
170+
* Useful when you want to display a certain field to the UI, but you want to use another field to query for Sorting.
171+
*/
163172
queryFieldSorter?: string;
164173

165174
/** Is the column resizable, can we make it wider/thinner? A resize cursor will show on the right side of the column when enabled. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SearchTerm } from './searchTerm.type';
22
import { Column } from './column.interface';
33
import { ColumnFilters } from './columnFilters.interface';
44
import { OperatorType } from './operatorType.enum';
5-
import { OperatorString } from 'dist/public_api';
5+
import { OperatorString } from './operatorString';
66

77
export interface FilterChangedArgs {
88
clearFilterTriggered?: boolean;

src/app/modules/angular-slickgrid/services/__tests__/graphql.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,8 @@ describe('CollectionService', () => {
821821
});
822822

823823
it('should return a query using a different field to query when the column has a "queryFieldFilter" defined in its definition', () => {
824-
const expectation = `query{users(first:10, offset:0, filterBy:[{field:isFemale, operator:EQ, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}`;
825-
const mockColumn = { id: 'gender', field: 'gender', queryFieldFilter: 'isFemale' } as Column;
824+
const expectation = `query{users(first:10, offset:0, filterBy:[{field:hasPriority, operator:EQ, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}`;
825+
const mockColumn = { id: 'gender', field: 'gender', queryField: 'isAfter', queryFieldFilter: 'hasPriority' } as Column;
826826
const mockColumnFilters = {
827827
gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female'], operator: 'EQ' },
828828
} as ColumnFilters;
@@ -914,7 +914,7 @@ describe('CollectionService', () => {
914914
totalCount,nodes{ id, company, gender, name } }}`;
915915
const mockColumnSort = [
916916
{ columnId: 'gender', sortCol: { id: 'gender', field: 'gender' }, sortAsc: false },
917-
{ columnId: 'name', sortCol: { id: 'name', field: 'name', queryFieldSorter: 'lastName' }, sortAsc: true }
917+
{ columnId: 'name', sortCol: { id: 'name', field: 'name', queryField: 'isAfter', queryFieldSorter: 'lastName' }, sortAsc: true }
918918
] as ColumnSort[];
919919

920920
service.init(serviceOptions, paginationOptions, gridStub);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class FilterService {
257257
}
258258

259259
const dataKey = columnDef.dataKey;
260-
const fieldName = columnDef.queryField || columnDef.queryFieldFilter || columnDef.field;
260+
const fieldName = columnDef.queryFieldFilter || columnDef.queryField || columnDef.field;
261261
const fieldType = columnDef.type || FieldType.string;
262262
const filterSearchType = (columnDef.filterSearchType) ? columnDef.filterSearchType : null;
263263
let cellValue = item[fieldName];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class GraphqlService implements BackendService {
364364
throw new Error('[GraphQL Service]: Something went wrong in trying to get the column definition of the specified filter (or preset filters). Did you make a typo on the filter columnId?');
365365
}
366366

367-
const fieldName = columnDef.queryField || columnDef.queryFieldFilter || columnDef.field || columnDef.name || '';
367+
const fieldName = columnDef.queryFieldFilter || columnDef.queryField || columnDef.field || columnDef.name || '';
368368
const searchTerms = columnFilter && columnFilter.searchTerms || [];
369369
let fieldSearchValue = (Array.isArray(searchTerms) && searchTerms.length === 1) ? searchTerms[0] : '';
370370
if (typeof fieldSearchValue === 'undefined') {
@@ -464,7 +464,7 @@ export class GraphqlService implements BackendService {
464464
const columnDef = this._columnDefinitions.find((column: Column) => column.id === sorter.columnId);
465465

466466
graphqlSorters.push({
467-
field: columnDef ? ((columnDef.queryField || columnDef.queryFieldSorter || columnDef.field) + '') : (sorter.columnId + ''),
467+
field: columnDef ? ((columnDef.queryFieldSorter || columnDef.queryField || columnDef.field) + '') : (sorter.columnId + ''),
468468
direction: sorter.direction
469469
});
470470

@@ -494,7 +494,7 @@ export class GraphqlService implements BackendService {
494494
});
495495

496496
graphqlSorters.push({
497-
field: (column.sortCol.queryField || column.sortCol.queryFieldSorter || column.sortCol.field) + '',
497+
field: (column.sortCol.queryFieldSorter || column.sortCol.queryField || column.sortCol.field) + '',
498498
direction: column.sortAsc ? SortDirection.ASC : SortDirection.DESC
499499
});
500500
}

src/app/modules/angular-slickgrid/services/grid-odata.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class GridOdataService implements BackendService {
203203
throw new Error('[Backend Service API]: Something went wrong in trying to get the column definition of the specified filter (or preset filters). Did you make a typo on the filter columnId?');
204204
}
205205

206-
let fieldName = columnDef.queryField || columnDef.queryFieldFilter || columnDef.field || columnDef.name || '';
206+
let fieldName = columnDef.queryFieldFilter || columnDef.queryField || columnDef.field || columnDef.name || '';
207207
const fieldType = columnDef.type || 'string';
208208
const searchTerms = (columnFilter ? columnFilter.searchTerms : null) || [];
209209
let fieldSearchValue = (Array.isArray(searchTerms) && searchTerms.length === 1) ? searchTerms[0] : '';
@@ -341,7 +341,7 @@ export class GridOdataService implements BackendService {
341341
const columnDef = this._columnDefinitions.find((column: Column) => column.id === sorter.columnId);
342342

343343
sorterArray.push({
344-
columnId: columnDef ? ((columnDef.queryField || columnDef.queryFieldSorter || columnDef.field || columnDef.id) + '') : (sorter.columnId + ''),
344+
columnId: columnDef ? ((columnDef.queryFieldSorter || columnDef.queryField || columnDef.field || columnDef.id) + '') : (sorter.columnId + ''),
345345
direction: sorter.direction
346346
});
347347

@@ -363,7 +363,7 @@ export class GridOdataService implements BackendService {
363363
if (sortColumns) {
364364
for (const columnDef of sortColumns) {
365365
if (columnDef.sortCol) {
366-
let fieldName = (columnDef.sortCol.queryField || columnDef.sortCol.queryFieldSorter || columnDef.sortCol.field || columnDef.sortCol.id) + '';
366+
let fieldName = (columnDef.sortCol.queryFieldSorter || columnDef.sortCol.queryField || columnDef.sortCol.field || columnDef.sortCol.id) + '';
367367
let columnFieldName = (columnDef.sortCol.field || columnDef.sortCol.id) + '';
368368
if (this.odataService.options.caseType === CaseType.pascalCase) {
369369
fieldName = String.titleCase(fieldName);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class SortService {
106106
this._slickSubscriber.subscribe((e: any, args: any) => {
107107
// multiSort and singleSort are not exactly the same, but we want to structure it the same for the (for loop) after
108108
// also to avoid having to rewrite the for loop in the sort, we will make the singleSort an array of 1 object
109-
const sortColumns = (args.multiColumnSort) ? args.sortCols : new Array({sortAsc: args.sortAsc, sortCol: args.sortCol});
109+
const sortColumns = (args.multiColumnSort) ? args.sortCols : new Array({ sortAsc: args.sortAsc, sortCol: args.sortCol });
110110

111111
// keep current sorters
112112
this._currentLocalSorters = []; // reset current local sorters
@@ -139,7 +139,7 @@ export class SortService {
139139
this.onBackendSortChanged(undefined, { grid: this._grid, sortCols: [] });
140140
} else {
141141
if (this._columnDefinitions && Array.isArray(this._columnDefinitions)) {
142-
this.onLocalSortChanged(this._grid, this._dataView, new Array({sortAsc: true, sortCol: this._columnDefinitions[0] }));
142+
this.onLocalSortChanged(this._grid, this._dataView, new Array({ sortAsc: true, sortCol: this._columnDefinitions[0] }));
143143
}
144144
}
145145
} else if (this._isBackendGrid) {
@@ -230,7 +230,7 @@ export class SortService {
230230
const columnSortObj = sortColumns[i];
231231
if (columnSortObj && columnSortObj.sortCol) {
232232
const sortDirection = columnSortObj.sortAsc ? SortDirectionNumber.asc : SortDirectionNumber.desc;
233-
const sortField = columnSortObj.sortCol.queryField || columnSortObj.sortCol.queryFieldSorter || columnSortObj.sortCol.field;
233+
const sortField = columnSortObj.sortCol.queryFieldSorter || columnSortObj.sortCol.queryField || columnSortObj.sortCol.field;
234234
const fieldType = columnSortObj.sortCol.type || FieldType.string;
235235
let value1 = dataRow1[sortField];
236236
let value2 = dataRow2[sortField];

0 commit comments

Comments
 (0)