Skip to content

Commit

Permalink
feat(search): fix the resolving of filteredSortedData #3519
Browse files Browse the repository at this point in the history
  • Loading branch information
DiyanDimitrov committed Jan 16, 2019
1 parent 4d96e41 commit 0c03b04
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 66 deletions.
34 changes: 7 additions & 27 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
if (this.rowSelectable) {
this.updateHeaderCheckboxStatusOnFilter(this._filteredData);
}

this.refreshSearch(true);
}

/**
Expand Down Expand Up @@ -1646,8 +1644,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
set sortingExpressions(value: ISortingExpression[]) {
this._sortingExpressions = cloneArray(value);
this.cdr.markForCheck();

this.refreshSearch(true);
}

/**
Expand Down Expand Up @@ -2166,6 +2162,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
protected _wheelListener = null;
protected _allowFiltering = false;
private _filteredData = null;
private _filteredSortedData = null;
private resizeHandler;
private columnListDiffer;
private _hiddenColumnsText = '';
Expand Down Expand Up @@ -3012,8 +3009,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.onRowAdded.emit({ data });
this._pipeTrigger++;
this.cdr.markForCheck();

this.refreshSearch();
}

/**
Expand Down Expand Up @@ -3070,7 +3065,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
// Data needs to be recalculated if transactions are in place
// If no transactions, `data` will be a reference to the grid getter, otherwise it will be stale
const dataAfterDelete = this.transactions.enabled ? this.dataWithAddedInTransactionRows : data;
this.refreshSearch();
if (dataAfterDelete.length % this.perPage === 0 && dataAfterDelete.length / this.perPage - 1 < this.page && this.page !== 0) {
this.page--;
}
Expand Down Expand Up @@ -3122,7 +3116,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.gridAPI.escape_editMode(this.id, editableCell.cellID);
}
this.cdr.markForCheck();
this.refreshSearch();
}
}
}
Expand All @@ -3148,7 +3141,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
}
this.gridAPI.update_row(value, this.id, rowSelector);
this.cdr.markForCheck();
this.refreshSearch();
}
}

Expand Down Expand Up @@ -4197,30 +4189,18 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
}

/**
* Returns an array containing the filtered data.
* Returns an array containing the filtered sorted data.
* ```typescript
* const filteredData = this.grid1.filteredSortedData;
* const filteredSortedData = this.grid1.filteredSortedData;
* ```
* @memberof IgxGridBaseComponent
*/
get filteredSortedData(): any[] {
return this.resolveFilteredSortedData();
return this._filteredSortedData;
}

/**
* @hidden
*/
protected resolveFilteredSortedData(): any[] {
let data: any[] = this.filteredData ? this.filteredData : this.data;
if (!this.filteredData && this.transactions.enabled) {
data = DataUtil.mergeTransactions(
cloneArray(data),
this.transactions.getAggregatedChanges(true),
this.primaryKey
);
}

return data;
set filteredSortedData(value: any[]) {
this._filteredSortedData = value;
this.refreshSearch(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length > 0" [igxColumnMovingDrop]="parentVirtDir" [attr.droppable]="true" id="left" class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
<ng-template igxGridFor let-rowData [igxGridForOf]="data | gridTransaction:id:pipeTrigger
| gridFiltering:filteringExpressionsTree:id:pipeTrigger
| gridSort:sortingExpressions:pipeTrigger
| gridSort:sortingExpressions:id:pipeTrigger
| gridPreGroupBy:groupingExpressions:groupingExpansionState:groupsExpanded:id:pipeTrigger
| gridPaging:page:perPage:id:pipeTrigger
| gridPostGroupBy:groupingExpressions:groupingExpansionState:groupsExpanded:id:groupsRecords:pipeTrigger
Expand Down
17 changes: 0 additions & 17 deletions projects/igniteui-angular/src/lib/grids/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ export class IgxGridComponent extends IgxGridBaseComponent implements OnInit, Do
}
this.cdr.detectChanges();
this.calculateGridSizes();
this.refreshSearch(true);
}

/**
Expand All @@ -486,7 +485,6 @@ export class IgxGridComponent extends IgxGridBaseComponent implements OnInit, Do
public clearGrouping(name?: string | Array<string>): void {
this._gridAPI.clear_groupby(this.id, name);
this.calculateGridSizes();
this.refreshSearch(true);
}

/**
Expand Down Expand Up @@ -719,21 +717,6 @@ export class IgxGridComponent extends IgxGridBaseComponent implements OnInit, Do
super.scrollTo(row, column);
}

/**
* @hidden
*/
protected resolveFilteredSortedData(): any[] {
let data: any[] = super.resolveFilteredSortedData();

if (this.sortingExpressions &&
this.sortingExpressions.length > 0) {

const sortingPipe = new IgxGridSortingPipe();
data = sortingPipe.transform(data, this.sortingExpressions, -1);
}
return data;
}

/**
* @hidden
*/
Expand Down
17 changes: 13 additions & 4 deletions projects/igniteui-angular/src/lib/grids/grid/grid.pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ import { IgxGridBaseComponent } from '../grid-base.component';
pure: true
})
export class IgxGridSortingPipe implements PipeTransform {
private gridAPI: IgxGridAPIService;

constructor(gridAPI: GridBaseAPIService<IgxGridBaseComponent>) {
this.gridAPI = <IgxGridAPIService>gridAPI;
}

constructor() { }
public transform(collection: any[], expressions: ISortingExpression[], id: string, pipeTrigger: number): any[] {
const grid = this.gridAPI.get(id);
let result: any[];

public transform(collection: any[], expressions: ISortingExpression[], pipeTrigger: number): any[] {
if (!expressions.length) {
return collection;
result = collection;
} else {
result = DataUtil.sort(cloneArray(collection), expressions);
}
grid.filteredSortedData = result;

return DataUtil.sort(cloneArray(collection), expressions);
return result;
}
}

Expand Down
1 change: 0 additions & 1 deletion projects/igniteui-angular/src/lib/grids/row.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ export class IgxRowComponent<T extends IgxGridBaseComponent> implements DoCheck
}
this.gridAPI.update_row(value, this.gridID, this.rowID);
this.cdr.markForCheck();
this.grid.refreshSearch();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
*/
public flatData: any[];

/**
* @hidden
*/
public processedFlatData: any[];

/**
* @hidden
*/
Expand Down Expand Up @@ -389,8 +384,6 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
this.onRowAdded.emit({ data });
this._pipeTrigger++;
this.cdr.markForCheck();

this.refreshSearch();
}
} else {
if (this.primaryKey && this.foreignKey) {
Expand Down Expand Up @@ -479,13 +472,6 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
return path.reverse();
}

/**
* @hidden
*/
protected resolveFilteredSortedData(): any[] {
return this.processedFlatData;
}

/**
* @hidden
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class IgxTreeGridFlatteningPipe implements PipeTransform {

grid.processedRootRecords = collection;
grid.processedRecords = new Map<any, ITreeGridRecord>();
grid.processedFlatData = [];

this.getFlatDataRecursive(collection, data, expandedLevels, expandedStates, id, true);

Expand Down Expand Up @@ -172,7 +171,6 @@ export class IgxTreeGridFlatteningPipe implements PipeTransform {
this.updateNonProcessedRecordExpansion(grid, hierarchicalRecord);

grid.processedRecords.set(hierarchicalRecord.rowID, hierarchicalRecord);
grid.processedFlatData.push(hierarchicalRecord.data);

this.getFlatDataRecursive(hierarchicalRecord.children, data, expandedLevels,
expandedStates, gridID, parentExpanded && hierarchicalRecord.expanded);
Expand Down Expand Up @@ -210,9 +208,21 @@ export class IgxTreeGridSortingPipe implements PipeTransform {
} else {
result = DataUtil.treeGridSort(hierarchicalData, expressions);
}
const filteredSortedData = [];
this.flattenTreeGridRecords(result, filteredSortedData);
grid.filteredSortedData = filteredSortedData;

return result;
}

private flattenTreeGridRecords(records: ITreeGridRecord[], flatData: any[]) {
if (records && records.length) {
for (const record of records) {
flatData.push(record.data);
this.flattenTreeGridRecords(record.children, flatData);
}
}
}
}

/** @hidden */
Expand Down

0 comments on commit 0c03b04

Please sign in to comment.