|
| 1 | +import { Component, ViewChild, ViewEncapsulation } from '@angular/core'; |
| 2 | +import { IgxGridComponent, IgxColumnComponent, GridCellMergeMode,DefaultMergeStrategy } from 'igniteui-angular'; |
| 3 | +import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive'; |
| 4 | + |
| 5 | +@Component({ |
| 6 | + encapsulation: ViewEncapsulation.None, |
| 7 | + selector: 'app-grid-cell-merge-custom-sample', |
| 8 | + styleUrls: ['./grid-cell-merge-custom-sample.component.scss'], |
| 9 | + templateUrl: './grid-cell-merge-custom-sample.component.html', |
| 10 | + imports: [ |
| 11 | + IgxGridComponent, |
| 12 | + IgxPreventDocumentScrollDirective, |
| 13 | + IgxColumnComponent |
| 14 | + ] |
| 15 | +}) |
| 16 | +export class GridCellMergeCustomSampleComponent { |
| 17 | + @ViewChild('grid1', { read: IgxGridComponent, static: true }) |
| 18 | + public grid1: IgxGridComponent; |
| 19 | + public data; |
| 20 | + public cellMergeMode: GridCellMergeMode = 'always'; |
| 21 | + public perProjectMergeStrategy = new PerProjectMergeStrategy(); |
| 22 | + constructor() { |
| 23 | + this.data = [ |
| 24 | + { ActionID: "1", ProjectName: "IOT Switch Project", ActionName: "Data Import", Type: "Request", Priority: "Low", Status: "New", Created: new Date("2017-03-25"), LastEdit: new Date("2017-05-08") }, |
| 25 | + { ActionID: "2", ProjectName: "IOT Switch Project", ActionName: "Reports", Type: "Request", Priority: "Low", Status: "New", Created: new Date("2017-03-14"), LastEdit: new Date("2017-03-15") }, |
| 26 | + { ActionID: "4", ProjectName: "IOT Switch Project", ActionName: "Multiple Settings", Type: "Request", Priority: "Low", Status: "Rejected", Created: new Date("2017-04-05"), LastEdit: new Date("2017-04-30") }, |
| 27 | + { ActionID: "3", ProjectName: "IOT Switch Project", ActionName: "Data Archiving", Type: "Request", Priority: "Medium", Status: "New", Created: new Date("2017-08-21"), LastEdit: new Date("2017-09-08") }, |
| 28 | + { ActionID: "5", ProjectName: "IOT Switch Project", ActionName: "Main Menu: Return Button", Type: "Bug", Priority: "Medium", Status: "Fixed", Created: new Date("2017-06-17"), LastEdit: new Date("2017-07-03") }, |
| 29 | + { ActionID: "6", ProjectName: "IOT Switch Project", ActionName: "Auto Turn Off", Type: "Bug", Priority: "Medium", Status: "New", Created: new Date("2017-04-12"), LastEdit: new Date("2017-05-27") }, |
| 30 | + { ActionID: "7", ProjectName: "VR Device", ActionName: "Higher DRI", Type: "Request", Priority: "Medium", Status: "New", Created: new Date("2016-08-11"), LastEdit: new Date("2016-08-11") }, |
| 31 | + { ActionID: "8", ProjectName: "VR Device", ActionName: "Accessible Power Button", Type: "Request", Priority: "Medium", Status: "New", Created: new Date("2016-07-13"), LastEdit: new Date("2016-07-14") }, |
| 32 | + { ActionID: "9", ProjectName: "VR Device", ActionName: "Additional options", Type: "Request", Priority: "High", Status: "Rejected", Created: new Date("2016-09-02"), LastEdit: new Date("2016-09-08") }, |
| 33 | + { ActionID: "10", ProjectName: "VR Device", ActionName: "Data Log", Type: "Request", Priority: "High", Status: "New", Created: new Date("2017-03-25"), LastEdit: new Date("2017-05-08") }, |
| 34 | + { ActionID: "12", ProjectName: "VR Device", ActionName: "Motion Blur", Type: "Bug", Priority: "High", Status: "New", Created: new Date("2017-03-25"), LastEdit: new Date("2017-05-08") }, |
| 35 | + { ActionID: "11", ProjectName: "VR Device", ActionName: "Left Sensors Delay", Type: "Bug", Priority: "High", Status: "Fixed", Created: new Date("2017-03-25"), LastEdit: new Date("2017-05-08") } |
| 36 | + ]; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +export class PerProjectMergeStrategy extends DefaultMergeStrategy { |
| 41 | + /* Merge only cells within their respective projects */ |
| 42 | + public override comparer(prevRecord: any, record: any, field: string): boolean { |
| 43 | + const a = prevRecord[field]; |
| 44 | + const b = record[field]; |
| 45 | + const projA = prevRecord['ProjectName']; |
| 46 | + const projB = record['ProjectName']; |
| 47 | + return a === b && projA === projB; |
| 48 | + } |
| 49 | +} |
0 commit comments