11import {
2- AfterViewInit , ChangeDetectorRef , Component , DebugElement , Injectable ,
3- OnInit , ViewChild , ViewChildren , QueryList , TemplateRef
2+ AfterViewInit , ChangeDetectorRef , Component , Injectable ,
3+ OnInit , ViewChild , TemplateRef
44} from '@angular/core' ;
5- import { async , TestBed , fakeAsync , tick , flush , ComponentFixture } from '@angular/core/testing' ;
5+ import { async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
66import { BehaviorSubject , Observable } from 'rxjs' ;
77import { By } from '@angular/platform-browser' ;
88import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
99import { IgxGridComponent } from './grid.component' ;
1010import { IgxRowComponent } from '../row.component' ;
11- import { IgxGridTransaction } from '../grid-base.component' ;
1211import { IgxColumnComponent } from '../column.component' ;
1312import { IForOfState } from '../../directives/for-of/for_of.directive' ;
1413import { IgxGridModule , GridSelectionMode } from './index' ;
@@ -17,14 +16,9 @@ import { DataType } from '../../data-operations/data-util';
1716import { GridTemplateStrings } from '../../test-utils/template-strings.spec' ;
1817import { SampleTestData , DataParent } from '../../test-utils/sample-test-data.spec' ;
1918import { BasicGridComponent } from '../../test-utils/grid-base-components.spec' ;
20- import { UIInteractions , wait } from '../../test-utils/ui-interactions.spec' ;
21- import {
22- IgxRowEditTabStopDirective
23- } from '../grid.rowEdit.directive' ;
19+ import { wait } from '../../test-utils/ui-interactions.spec' ;
2420import { IgxStringFilteringOperand , IgxNumberFilteringOperand } from '../../data-operations/filtering-condition' ;
2521import { SortingDirection } from '../../data-operations/sorting-expression.interface' ;
26- import { IgxGridCellComponent } from '../cell.component' ;
27- import { IgxTransactionService } from '../../services' ;
2822import { configureTestSuite } from '../../test-utils/configure-suite' ;
2923import { IgxTabsModule , IgxTabsComponent } from '../../tabs' ;
3024import { resizeObserverIgnoreError } from '../../test-utils/helper-utils.spec' ;
@@ -1406,8 +1400,7 @@ describe('IgxGrid Component Tests #grid', () => {
14061400 beforeEach ( async ( ( ) => {
14071401 TestBed . configureTestingModule ( {
14081402 declarations : [
1409- IgxGridDefaultRenderingComponent ,
1410- IgxGridRowEditingTransactionComponent
1403+ IgxGridDefaultRenderingComponent
14111404 ] ,
14121405 imports : [
14131406 NoopAnimationsModule , IgxGridModule ]
@@ -2052,238 +2045,6 @@ export class IgxGridFormattingComponent extends BasicGridComponent {
20522045 }
20532046}
20542047
2055- @Component ( {
2056- template : `
2057- <igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="900px" height="300px" [rowEditable]="true">
2058- <igx-column field="ProductID" header="Product ID"></igx-column>
2059- <igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" width="100px">
2060- </igx-column>
2061- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" [sortable]="true" width="150px">
2062- </igx-column>
2063- <igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px"></igx-column>
2064- </igx-grid>`
2065- } )
2066- export class IgxBasicGridRowEditingComponent {
2067- public data = SampleTestData . foodProductData ( ) ;
2068-
2069- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2070- }
2071-
2072- @Component ( {
2073- template : `
2074- <igx-grid #grid [data]="data" [primaryKey]="'ProductID'"
2075- width="900px" height="600px" [rowEditable]="true" >
2076- <igx-column field="ProductID" header="Product ID" [editable]="false" width="200px"></igx-column>
2077- <igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" editable="true" width="100px">
2078- </igx-column>
2079- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" editable="true" [sortable]="true" width="200px">
2080- </igx-column>
2081- <igx-column field="OrderDate" header="Order Date" [dataType]="'date'" editable="true" width="200px"></igx-column>
2082- </igx-grid>`
2083- } )
2084- export class IgxGridRowEditingComponent {
2085- public data = SampleTestData . foodProductData ( ) ;
2086- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2087- }
2088-
2089- @Component ( {
2090- template : `
2091- <igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="700px" height="400px" [rowEditable]="true">
2092- <igx-column>
2093- <ng-template igxCell let-cell="cell" let-val>
2094- <button>Delete</button>
2095- </ng-template>
2096- </igx-column>
2097- <igx-column field="ProductID" header="Product ID"></igx-column>
2098- <igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
2099- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
2100- <igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
2101- </igx-grid>`
2102- } )
2103- export class IgxGridRowEditingWithoutEditableColumnsComponent {
2104- public data = SampleTestData . foodProductData ( ) ;
2105- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2106- }
2107-
2108- @Component ( {
2109- template : `
2110- <igx-grid #grid [data]="data" [primaryKey]="'ID'" width="700px" height="400px" [rowEditable]="true">
2111- <igx-column
2112- field="Downloads" header="Downloads" [dataType]="'number'" [pinned]="pinnedFlag" [editable]="true">
2113- </igx-column>
2114- <igx-column field="ID" header="ID" [dataType]="'number'"
2115- [editable]="false" [pinned]="pinnedFlag" [hidden]="hiddenFlag" width="60px">
2116- </igx-column>
2117- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" [editable]="false" [hidden]="hiddenFlag" width="150px">
2118- </igx-column>
2119- <igx-column field="ReleaseDate" header="Release Date" [dataType]="'date'" [editable]="true" [hidden]="hiddenFlag" width="150px">
2120- </igx-column>
2121- <igx-column-group [movable]="true" header="Column Group 1" *ngIf="columnGroupingFlag">
2122- <igx-column field="Released" header="Released" [dataType]="'boolean'" [pinned]="pinnedFlag" [editable]="true" width="100px">
2123- </igx-column>
2124- <igx-column field="Category" header="Category" [dataType]="'string'" [editable]="false" [hidden]="hiddenFlag" width="150px">
2125- </igx-column>
2126- </igx-column-group>
2127- <ng-container *ngIf="!columnGroupingFlag">
2128- <igx-column field="Released" header="Released" [dataType]="'boolean'" [pinned]="pinnedFlag" [editable]="true" width="100px">
2129- </igx-column>
2130- <igx-column field="Category" header="Category" [dataType]="'string'" [editable]="true" [hidden]="hiddenFlag" width="150px">
2131- </igx-column>
2132- </ng-container>
2133- <igx-column field="Items" header="Items" [dataType]="'string'" [editable]="true" width="150px">
2134- </igx-column>
2135- <igx-column field="Test" header="Test" [dataType]="'string'" [editable]="true" [hidden]="hiddenFlag" width="150px">
2136- </igx-column>
2137- </igx-grid>`
2138- } )
2139- export class IgxGridWithEditingAndFeaturesComponent {
2140- /* Data fields: Downloads:number, ID: number, ProductName: string, ReleaseDate: Date,
2141- Released: boolean, Category: string, Items: string, Test: string. */
2142- public pinnedFlag = false ;
2143- public hiddenFlag = false ;
2144- public columnGroupingFlag = false ;
2145- public data = SampleTestData . generateProductData ( 11 ) ;
2146- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2147- public moveNext ( shiftKey : boolean ) : void {
2148- UIInteractions . triggerKeyDownWithBlur ( 'tab' , this . getCurrentEditCell ( ) . nativeElement , true , false , shiftKey ) ;
2149- }
2150- public focusGridCell ( rowIndex : number , columnName : string ) : IgxGridCellComponent {
2151- const targetCell = this . getCell ( rowIndex , columnName ) ;
2152- targetCell . onFocus ( new FocusEvent ( 'focus' ) ) ;
2153- return targetCell ;
2154- }
2155-
2156- public getCell ( rowIndex : number , columnName : string ) : IgxGridCellComponent {
2157- return this . grid . getCellByColumn ( rowIndex , columnName ) ;
2158- }
2159-
2160- public getCurrentEditCell ( ) : IgxGridCellComponent {
2161- const grid = this . grid as any ;
2162- const currentCell = grid . gridAPI . get_cell_inEditMode ( ) ;
2163- return this . grid . getCellByColumn ( currentCell . id . rowIndex , currentCell . column . field ) ;
2164- }
2165-
2166- public get gridAPI ( ) {
2167- return ( < any > this . grid ) . gridAPI ;
2168- }
2169-
2170- public get cellInEditMode ( ) {
2171- return this . grid . crudService . cell ;
2172- }
2173- }
2174-
2175- @Component ( {
2176- template : `
2177- <igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="700px" height="400px" [rowEditable]="true">
2178- <igx-column field="ProductID" header="Product ID"></igx-column>
2179- <igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
2180- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
2181- <igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
2182- <ng-template igxRowEdit let-rowChangesCount="rowChangesCount" let-endEdit="endEdit">
2183- <div class="igx-banner__message">
2184- <span class="igx-banner__text">{{ rowChangesCount }} </span>
2185- </div>
2186- <div class="igx-banner__actions">
2187- <div class="igx-banner__row">
2188- <button igxButton igxRowEditTabStop (click)="endEdit(false)">Cancel</button>
2189- <button igxButton igxRowEditTabStop (click)="endEdit(true)">Done</button>
2190- </div>
2191- </div>
2192- </ng-template>
2193- </igx-grid>
2194- `
2195- } )
2196- export class IgxGridCustomOverlayComponent {
2197- public data = SampleTestData . foodProductData ( ) ;
2198- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2199- @ViewChildren ( IgxRowEditTabStopDirective ) public buttons : QueryList < IgxRowEditTabStopDirective > ;
2200-
2201- public get gridAPI ( ) {
2202- return ( < any > this . grid ) . gridAPI ;
2203- }
2204-
2205- public get cellInEditMode ( ) {
2206- return this . gridAPI . get_cell_inEditMode ( ) ;
2207- }
2208-
2209- public getCurrentEditCell ( ) : IgxGridCellComponent {
2210- const grid = this . grid as any ;
2211- const currentCell = grid . gridAPI . get_cell_inEditMode ( ) ;
2212- return this . grid . getCellByColumn ( currentCell . id . rowIndex , currentCell . column . field ) ;
2213- }
2214-
2215- public moveNext ( shiftKey : boolean ) : void {
2216- this . getCurrentEditCell ( ) . dispatchEvent ( new KeyboardEvent ( 'keydown' , {
2217- key : 'tab' ,
2218- code : 'tab' ,
2219- shiftKey
2220- } ) ) ;
2221- }
2222- }
2223-
2224- @Component ( {
2225- template : `
2226- <igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="900px" height="900px" [rowEditable]="true"
2227- [paging]="paging" [perPage]="7">
2228- <igx-column field="ProductID" header="Product ID" width="150px"></igx-column>
2229- <igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="200px"></igx-column>
2230- <igx-column field="InStock" header="In Stock" [dataType]="'boolean'" width="100px"></igx-column>
2231- <igx-column field="UnitsInStock" header="Units in Stock" [dataType]="'number'" width="150px"></igx-column>
2232- <igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="200px"></igx-column>
2233- </igx-grid>` ,
2234- providers : [ { provide : IgxGridTransaction , useClass : IgxTransactionService } ] ,
2235- } )
2236- export class IgxGridRowEditingTransactionComponent {
2237- public data = SampleTestData . foodProductData ( ) ;
2238- @ViewChild ( 'grid' , { read : IgxGridComponent , static : true } ) public grid : IgxGridComponent ;
2239-
2240- public paging = false ;
2241- }
2242-
2243- @Component ( {
2244- template : `
2245- <igx-grid
2246- [width]='width'
2247- [height]='height'
2248- [data]="data"
2249- [autoGenerate]="true" (onColumnInit)="columnsCreated($event)" (onGroupingDone)="onGroupingDoneHandler($event)"
2250- [rowEditable]="enableRowEditing">
2251- </igx-grid>
2252- <ng-template #dropArea>
2253- <span> Custom template </span>
2254- </ng-template>
2255- `
2256- } )
2257- export class IgxGridRowEditingWithFeaturesComponent extends DataParent {
2258- public width = '800px' ;
2259- public height = null ;
2260-
2261- @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
2262- public instance : IgxGridComponent ;
2263-
2264- @ViewChild ( 'dropArea' , { read : TemplateRef , static : true } )
2265- public dropAreaTemplate : TemplateRef < any > ;
2266-
2267- public enableSorting = false ;
2268- public enableFiltering = false ;
2269- public enableResizing = false ;
2270- public enableEditing = true ;
2271- public enableGrouping = true ;
2272- public enableRowEditing = true ;
2273- public currentSortExpressions ;
2274-
2275- public columnsCreated ( column : IgxColumnComponent ) {
2276- column . sortable = this . enableSorting ;
2277- column . filterable = this . enableFiltering ;
2278- column . resizable = this . enableResizing ;
2279- column . editable = this . enableEditing ;
2280- column . groupable = this . enableGrouping ;
2281- }
2282- public onGroupingDoneHandler ( sortExpr ) {
2283- this . currentSortExpressions = sortExpr ;
2284- }
2285- }
2286-
22872048@Component ( {
22882049 template : `
22892050 <div style="width: 600px; height: 400px;">
0 commit comments