Skip to content

Commit 3be2eb1

Browse files
MKirovaMKirova
authored andcommitted
feat(igxGrid): Include "Add Row" button to empty/filtered grid templates.
1 parent 5a3db88 commit 3be2eb1

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

projects/igniteui-angular/src/lib/core/i18n/grid-resources.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface IGridResourceStrings {
102102
igx_grid_snackbar_addrow_actiontext?: string;
103103
igx_grid_actions_edit_label?: string;
104104
igx_grid_actions_add_label?: string;
105+
igx_grid_add_row_label?: string;
105106
igx_grid_actions_add_child_label?: string;
106107
igx_grid_actions_delete_label?: string;
107108
igx_grid_actions_pin_label?: string;
@@ -214,6 +215,7 @@ export const GridResourceStringsEN: IGridResourceStrings = {
214215
igx_grid_snackbar_addrow_actiontext: 'SHOW',
215216
igx_grid_actions_edit_label: 'Edit',
216217
igx_grid_actions_add_label: 'Add',
218+
igx_grid_add_row_label: 'ADD ROW',
217219
igx_grid_actions_add_child_label: 'Add Child',
218220
igx_grid_actions_delete_label: 'Delete',
219221
igx_grid_actions_pin_label: 'Pin',

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@
942942
align-items: center;
943943
height: 100%;
944944
color: --var($theme, 'content-text-color');
945+
flex-direction: column;
945946
}
946947

947948
%igx-grid__loading {

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
271271
@Input()
272272
public emptyGridTemplate: TemplateRef<any>;
273273

274+
/**
275+
* Gets/Sets a custom template for adding row UI when grid is empty.
276+
* @example
277+
* ```html
278+
* <igx-grid [id]="'igx-grid-1'" [data]="Data" [addRowEmptyGridTemplate]="myTemplate" [autoGenerate]="true"></igx-grid>
279+
* ```
280+
*/
281+
@Input()
282+
public addRowEmptyGridTemplate: TemplateRef<any>;
283+
274284
/**
275285
* Gets/Sets a custom template when loading.
276286
* @example

projects/igniteui-angular/src/lib/grids/grid/grid.component.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,27 @@
251251
</ng-template>
252252

253253
<ng-template #emptyFilteredGrid>
254-
<span class="igx-grid__tbody-message">{{emptyFilteredGridMessage}}</span>
254+
<span class="igx-grid__tbody-message">
255+
<span>{{emptyFilteredGridMessage}}</span>
256+
<span *ngIf='rowEditable && dataView.length === 0'>
257+
<ng-container *ngTemplateOutlet='addRowEmptyTemplate'></ng-container>
258+
</span>
259+
</span>
255260
</ng-template>
256261

257262
<ng-template #defaultEmptyGrid>
258-
<span class="igx-grid__tbody-message">{{emptyGridMessage}}</span>
263+
<span class="igx-grid__tbody-message">
264+
<span>{{emptyGridMessage}}</span>
265+
<span *ngIf='rowEditable && dataView.length === 0'>
266+
<ng-container *ngTemplateOutlet='addRowEmptyGridTemplate || defaultAddRowEmptyTemplate'></ng-container>
267+
</span>
268+
</span>
269+
</ng-template>
270+
271+
<ng-template #defaultAddRowEmptyTemplate>
272+
<button igxButton="raised" igxRipple (click)='beginAddRowByIndex(null, -1)'>
273+
{{resourceStrings.igx_grid_add_row_label}}
274+
</button>
259275
</ng-template>
260276

261277
<ng-template #defaultLoadingGrid>

src/app/grid-add-row/grid-add-row.sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
(mouseleave)="onMouseLeave(actionstrip)"
1010
(mouseover)="onMouseOver($event, grid, actionstrip)"
1111
[rowEditable]="true"
12+
[allowFiltering]="true"
1213
>
1314
<igx-column
1415
*ngFor="let c of columns"

src/app/grid-add-row/grid-add-row.sample.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export class GridAddRowSampleComponent implements OnInit {
6565
{ 'ID': 'FRANR', 'CompanyName': 'France restauration', 'ContactName': 'Carine Schmitt', 'ContactTitle': 'Marketing Manager', 'Address': '54, rue Royale', 'City': 'Nantes', 'Region': null, 'PostalCode': '44000', 'Country': 'France', 'Phone': '40.32.21.21', 'Fax': '40.32.21.20' },
6666
{ 'ID': 'FRANS', 'CompanyName': 'Franchi S.p.A.', 'ContactName': 'Paolo Accorti', 'ContactTitle': 'Sales Representative', 'Address': 'Via Monte Bianco 34', 'City': 'Torino', 'Region': null, 'PostalCode': '10100', 'Country': 'Italy', 'Phone': '011-4988260', 'Fax': '011-4988261' }
6767
];
68+
69+
this.data = [];
6870
// tslint:enable:max-line-length
6971
}
7072
}

0 commit comments

Comments
 (0)