Skip to content

Commit

Permalink
fix(plugins): add missing Row Detail filtering code (#239)
Browse files Browse the repository at this point in the history
* fix(plugins): add missing Row Detail filtering code
- get the item data context from its parrent object when using row detail
  • Loading branch information
ghiscoding authored Jan 20, 2021
1 parent 8c9cb84 commit d9cad63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/interfaces/gridOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
HeaderMenu,
Locale,
Pagination,
// RowDetailView,
RowDetailView,
RowMoveManager,
RowSelectionModelOption,
TextExportOption,
Expand Down Expand Up @@ -435,7 +435,7 @@ export interface GridOption {
registerExternalResources?: ExternalResource[];

/** Row Detail View Plugin options & events (columnId, cssClass, toolTip, width) */
// rowDetailView?: RowDetailView;
rowDetailView?: RowDetailView;

/** Grid row height in pixels (only type the number). Row of cell values. */
rowHeight?: number;
Expand Down
47 changes: 24 additions & 23 deletions packages/common/src/services/__tests__/filter.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
GridMenuItem,
GridOption,
MenuCommandItem,
RowDetailView,
SlickDataView,
SlickEventHandler,
SlickGrid,
Expand Down Expand Up @@ -755,34 +756,34 @@ describe('FilterService', () => {
expect(output).toBe(true);
});

// it('should return True when using row detail and the item is found in its parent', () => {
// gridOptionMock.enableRowDetailView = true;
// const mockColumn1 = { id: 'zip', field: 'zip', filterable: true, queryFieldFilter: 'address.zip' } as Column;
// const mockItem2 = { __isPadding: true, __parent: mockItem1 };
// jest.spyOn(gridStub, 'getColumns').mockReturnValue([mockColumn1]);
// jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(0);
it('should return True when using row detail and the item is found in its parent', () => {
gridOptionMock.enableRowDetailView = true;
const mockColumn1 = { id: 'zip', field: 'zip', filterable: true, queryFieldFilter: 'address.zip' } as Column;
const mockItem2 = { __isPadding: true, __parent: mockItem1 };
jest.spyOn(gridStub, 'getColumns').mockReturnValue([mockColumn1]);
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(0);

// service.init(gridStub);
// const columnFilters = { zip: { columnDef: mockColumn1, columnId: 'zip', operator: 'EQ', searchTerms: [123456] } };
// const output = service.customLocalFilter(mockItem2, { dataView: dataViewStub, grid: gridStub, columnFilters });
service.init(gridStub);
const columnFilters = { zip: { columnDef: mockColumn1, columnId: 'zip', operator: 'EQ', searchTerms: [123456] } };
const output = service.customLocalFilter(mockItem2, { dataView: dataViewStub, grid: gridStub, columnFilters });

// expect(output).toBe(true);
// });
expect(output).toBe(true);
});

// it('should return True when using row detail custom "keyPrefix" and the item is found in its parent', () => {
// gridOptionMock.rowDetailView = { keyPrefix: 'prefix_' } as RowDetail;
// gridOptionMock.enableRowDetailView = true;
// const mockColumn1 = { id: 'zip', field: 'zip', filterable: true, queryFieldFilter: 'address.zip' } as Column;
// const mockItem2 = { prefix_isPadding: true, prefix_parent: mockItem1 };
// jest.spyOn(gridStub, 'getColumns').mockReturnValue([mockColumn1]);
// jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(0);
it('should return True when using row detail custom "keyPrefix" and the item is found in its parent', () => {
gridOptionMock.rowDetailView = { keyPrefix: 'prefix_' } as RowDetailView;
gridOptionMock.enableRowDetailView = true;
const mockColumn1 = { id: 'zip', field: 'zip', filterable: true, queryFieldFilter: 'address.zip' } as Column;
const mockItem2 = { prefix_isPadding: true, prefix_parent: mockItem1 };
jest.spyOn(gridStub, 'getColumns').mockReturnValue([mockColumn1]);
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(0);

// service.init(gridStub);
// const columnFilters = { zip: { columnDef: mockColumn1, columnId: 'zip', operator: 'EQ', searchTerms: [123456] } };
// const output = service.customLocalFilter(mockItem2, { dataView: dataViewStub, grid: gridStub, columnFilters });
service.init(gridStub);
const columnFilters = { zip: { columnDef: mockColumn1, columnId: 'zip', operator: 'EQ', searchTerms: [123456] } };
const output = service.customLocalFilter(mockItem2, { dataView: dataViewStub, grid: gridStub, columnFilters });

// expect(output).toBe(true);
// });
expect(output).toBe(true);
});

it('should execute "queryFieldNameGetterFn()" callback and return True when input value matches the full name', () => {
const mockColumn1 = { id: 'name', field: 'name', filterable: true, queryFieldNameGetterFn: () => 'fullName' } as Column;
Expand Down
12 changes: 6 additions & 6 deletions packages/common/src/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ export class FilterService {
}

// Row Detail View plugin, if the row is padding we just get the value we're filtering on from it's parent
// if (this._gridOptions.enableRowDetailView) {
// const metadataPrefix = this._gridOptions.rowDetailView && this._gridOptions.rowDetailView.keyPrefix || '__';
// if (item[`${metadataPrefix}isPadding`] && item[`${metadataPrefix}parent`]) {
// item = item[`${metadataPrefix}parent`];
// }
// }
if (this._gridOptions.enableRowDetailView) {
const metadataPrefix = this._gridOptions.rowDetailView && this._gridOptions.rowDetailView.keyPrefix || '__';
if (item[`${metadataPrefix}isPadding`] && item[`${metadataPrefix}parent`]) {
item = item[`${metadataPrefix}parent`];
}
}

const dataKey = columnDef.dataKey;
let queryFieldName = columnDef.filter?.queryField || columnDef.queryFieldFilter || columnDef.queryField || columnDef.field || '';
Expand Down

0 comments on commit d9cad63

Please sign in to comment.