Skip to content

Commit 4285471

Browse files
authored
Merge pull request #3045 from IgniteUI/ttonev/grid-excel-style-editing-vnext
Ttonev/grid excel style editing vnext
2 parents 1b2f4b0 + c66f21e commit 4285471

7 files changed

Lines changed: 184 additions & 0 deletions

File tree

live-editing/configs/GridConfigGenerator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,16 @@ export class GridConfigGenerator implements IConfigGenerator {
473473
})
474474
}));
475475

476+
configs.push(new Config({
477+
component: 'GridExcelStyleEditingComponent',
478+
additionalFiles: ['/src/app/directives/prevent-scroll.directive.ts', '/src/app/data/nwindData.ts'],
479+
appModuleConfig: new AppModuleConfig({
480+
imports: ['GridExcelStyleEditingComponent', 'IgxGridModule', 'IgxPreventDocumentScrollModule'],
481+
ngDeclarations: ['GridExcelStyleEditingComponent'],
482+
ngImports: ['IgxPreventDocumentScrollModule', 'IgxGridModule']
483+
})
484+
}));
485+
476486
configs.push(new Config({
477487
component: 'GridEditingStyleSampleComponent',
478488
additionalFiles: ['/src/app/directives/prevent-scroll.directive.ts', '/src/app/data/nwindData.ts'],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<div class="grid__wrapper">
2+
<igx-grid
3+
igxPreventDocumentScroll
4+
#grid
5+
[data]="data"
6+
[primaryKey]="'ProductID'"
7+
width="100%"
8+
height="500px"
9+
(keydown)="keydownHandler($event)"
10+
(activeNodeChange)="activeNodeChange()"
11+
>
12+
<igx-column
13+
field="ProductID"
14+
header="Product ID"
15+
[editable]="true"
16+
[groupable]="true"
17+
[hidden]="true"
18+
></igx-column>
19+
<igx-column
20+
field="ProductName"
21+
header="Product Name"
22+
[groupable]="true"
23+
[dataType]="'string'"
24+
[editable]="true"
25+
></igx-column>
26+
<igx-column
27+
field="UnitPrice"
28+
header="Unit Price"
29+
[groupable]="true"
30+
[dataType]="'string'"
31+
[editable]="true"
32+
></igx-column>
33+
<igx-column
34+
field="QuantityPerUnit"
35+
header="Quantity Per Unit"
36+
[groupable]="true"
37+
[dataType]="'string'"
38+
[editable]="true"
39+
></igx-column>
40+
<igx-column
41+
field="ReorderLevel"
42+
header="Reorder Level"
43+
dataType="number"
44+
[groupable]="true"
45+
[editable]="true"
46+
></igx-column>
47+
</igx-grid>
48+
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.grid__wrapper {
2+
padding: 16px;
3+
}
4+
5+
h4 {
6+
text-align: center;
7+
padding-top: 2%;
8+
padding-bottom: 2%;
9+
}
10+
.buttons-row {
11+
display: flex;
12+
flex-direction: row;
13+
justify-content: space-between;
14+
padding: 5px;
15+
}
16+
.buttons-wrapper {
17+
display: flex;
18+
flex-direction: row;
19+
justify-content: center;
20+
padding: 10px 0;
21+
}
22+
23+
.transaction--update, .transaction--delete, .transaction--add {
24+
font-weight: 600;
25+
}
26+
.transaction--add {
27+
color: #6b3;
28+
}
29+
.transaction--update {
30+
color: #4a71b9;
31+
}
32+
.transaction--delete {
33+
color: #ee4920;
34+
}
35+
.transaction-log {
36+
word-wrap: none;
37+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
2+
import {
3+
IgxDialogComponent,
4+
IgxGridComponent,
5+
Transaction
6+
} from 'igniteui-angular';
7+
import { DATA } from './../../data/nwindData';
8+
9+
@Component({
10+
selector: 'app-grid-excel-style-editing-sample',
11+
styleUrls: [`grid-editing-excel-style.component.scss`],
12+
templateUrl: 'grid-editing-excel-style.component.html'
13+
})
14+
export class GridExcelStyleEditingComponent implements OnInit {
15+
@ViewChild('grid', { read: IgxGridComponent, static: true })
16+
public grid: IgxGridComponent;
17+
18+
public data: any[];
19+
20+
public ngOnInit(): void {
21+
this.data = DATA;
22+
}
23+
24+
constructor(private cdr:ChangeDetectorRef){}
25+
26+
public keydownHandler(event) {
27+
const key = event.keyCode;
28+
const grid = this.grid;
29+
const activeElem = grid.navigation.activeNode;
30+
31+
if (
32+
(key >= 48 && key <= 57) ||
33+
(key >= 65 && key <= 90) ||
34+
(key >= 97 && key <= 122)
35+
) {
36+
// Number or Alphabet upper case or Alphabet lower case
37+
38+
const columnName = grid.getColumnByVisibleIndex(activeElem.column).field;
39+
const cell = grid.getCellByColumn(activeElem.row, columnName);
40+
if (cell && !grid.crudService.cellInEditMode) {
41+
grid.crudService.enterEditMode(cell);
42+
cell.editValue = event.key;
43+
}
44+
}
45+
46+
if (key == 13) {
47+
let thisRow = activeElem.row;
48+
const column = activeElem.column;
49+
const rowInfo = grid.dataView;
50+
51+
let nextRow = this.getNextEditableRowIndex(thisRow, rowInfo, event.shiftKey);
52+
53+
this.grid.navigateTo(nextRow, column, (obj) => {
54+
obj.target.activate();
55+
this.grid.clearCellSelection();
56+
this.cdr.detectChanges();
57+
});
58+
}
59+
}
60+
61+
public activeNodeChange() {
62+
this.grid.clearCellSelection();
63+
this.grid.endEdit();
64+
}
65+
66+
public getNextEditableRowIndex(currentRowIndex, dataView, previous){
67+
if (currentRowIndex < 0 || (currentRowIndex === 0 && previous) || (currentRowIndex >= dataView.length - 1 && !previous)) {
68+
return currentRowIndex;
69+
}
70+
if(previous){
71+
return dataView.findLastIndex((rec, index) => index < currentRowIndex && this.isEditableDataRecordAtIndex(index, dataView));
72+
}
73+
return dataView.findIndex((rec, index) => index > currentRowIndex && this.isEditableDataRecordAtIndex(index, dataView));
74+
}
75+
76+
private isEditableDataRecordAtIndex(dataViewIndex, dataView) {
77+
const rec = dataView[dataViewIndex];
78+
return !rec.expression && !rec.summaries && !rec.childGridsData && !rec.detailsData
79+
}
80+
}

src/app/grid/grid-routes-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const gridsRoutesData = {
88
'grid-groupby-summary': { displayName: 'Grid GroupBy Summary', parentName: 'Grid' },
99
'grid-groupby-summary-styling': { displayName: 'Grid GroupBy Summary Styling', parentName: 'Grid' },
1010
'grid-editing': { displayName: 'Grid Editing', parentName: 'Grid' },
11+
'grid-editing-excel-style': { displayName: 'Grid Excel Style Editing', parentName: 'Grid' },
1112
'grid-editing-events': { displayName: 'Grid Editing Events', parentName: 'Grid' },
1213
'grid-editing-style': { displayName: 'Grid Editing Style', parentName: 'Grid' },
1314
'grid-row-editing': { displayName: 'Grid Row Editing', parentName: 'Grid' },

src/app/grid/grids-routing.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ import { CRUDSampleComponent } from './grid-crud-sample/crud-sample.component';
121121
import { GridRowClassesComponent } from './grid-rowClasses-sample/grid-rowClasses.component';
122122
import { GridRowStylesComponent } from './grid-rowStyles-sample/grid-rowStyles.component';
123123
import { GridSummaryTemplateComponent } from './grid-summary-template/grid-summary-template.component';
124+
import { GridExcelStyleEditingComponent } from './grid-editing-excel-style/grid-editing-excel-style.component';
124125
// tslint:enable:max-line-length
125126

126127
export const gridsRoutes: Routes = [
@@ -169,6 +170,11 @@ export const gridsRoutes: Routes = [
169170
data: gridsRoutesData['grid-editing-style'],
170171
path: 'grid-editing-style'
171172
},
173+
{
174+
component: GridExcelStyleEditingComponent,
175+
data: gridsRoutesData['grid-editing-excel-style'],
176+
path: 'grid-editing-excel-style'
177+
},
172178
{
173179
component: GridAddRowSampleComponent,
174180
data: gridsRoutesData['grid-add-row'],

src/app/grid/grids.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import { CRUDSampleComponent } from './grid-crud-sample/crud-sample.component';
130130
import { GridRowClassesComponent } from './grid-rowClasses-sample/grid-rowClasses.component';
131131
import { GridRowStylesComponent } from './grid-rowStyles-sample/grid-rowStyles.component';
132132
import { GridSummaryTemplateComponent } from './grid-summary-template/grid-summary-template.component';
133+
import { GridExcelStyleEditingComponent } from './grid-editing-excel-style/grid-editing-excel-style.component';
133134

134135
@NgModule({
135136
declarations: [
@@ -167,6 +168,7 @@ import { GridSummaryTemplateComponent } from './grid-summary-template/grid-summa
167168
GridAddRowSampleComponent,
168169
GridEditingStyleSampleComponent,
169170
GridEditingEventsComponent,
171+
GridExcelStyleEditingComponent,
170172
FinancialSampleComponent,
171173
GridSample3Component,
172174
GridRemoteVirtualizationSampleComponent,

0 commit comments

Comments
 (0)