@@ -12,6 +12,8 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
12
12
import { IgxGridHeaderGroupComponent } from '../headers/grid-header-group.component' ;
13
13
import { IGridCellEventArgs } from '../common/events' ;
14
14
import { IgxColumnComponent } from '../columns/column.component' ;
15
+ import { ColumnPinningPosition } from '../common/enums' ;
16
+ import { IPinningConfig } from '../common/grid.interface' ;
15
17
16
18
describe ( 'IgxGrid - Column Pinning #grid ' , ( ) => {
17
19
configureTestSuite ( ) ;
@@ -412,6 +414,54 @@ describe('IgxGrid - Column Pinning #grid ', () => {
412
414
} ) ) ;
413
415
} ) ;
414
416
417
+ describe ( 'IgxGrid - Column Pinning to End' , ( ) => {
418
+ configureTestSuite ( ) ;
419
+
420
+ const COLUMN_HEADER_CLASS = '.igx-grid__th' ;
421
+ const FIRST_PINNED_CELL_CSS = 'igx-grid__td--pinned-first' ;
422
+
423
+ beforeAll ( async ( ( ) => {
424
+ TestBed . configureTestingModule ( {
425
+ declarations : [
426
+ GridRightPinningComponent
427
+ ] ,
428
+ imports : [ NoopAnimationsModule , IgxGridModule ]
429
+ } ) . compileComponents ( ) ;
430
+ } ) ) ;
431
+
432
+ it ( 'should correctly initialize when there are initially pinned columns.' , fakeAsync ( ( ) => {
433
+ const fix = TestBed . createComponent ( GridRightPinningComponent ) ;
434
+
435
+ tick ( ) ;
436
+ fix . detectChanges ( ) ;
437
+ const grid = fix . componentInstance . instance ;
438
+ const firstPinnedIndex = grid . unpinnedColumns . length ;
439
+ const secondPinnedIndex = grid . unpinnedColumns . length + 1 ;
440
+ // verify pinned/unpinned collections
441
+ expect ( grid . pinnedColumns . length ) . toEqual ( 2 ) ;
442
+ expect ( grid . unpinnedColumns . length ) . toEqual ( 9 ) ;
443
+
444
+ // verify DOM
445
+ const firstIndexCell = grid . getCellByColumn ( 0 , 'CompanyName' ) ;
446
+ expect ( firstIndexCell . visibleColumnIndex ) . toEqual ( firstPinnedIndex ) ;
447
+ expect ( firstIndexCell . nativeElement . classList . contains ( FIRST_PINNED_CELL_CSS ) ) . toBe ( true ) ;
448
+
449
+ const lastIndexCell = grid . getCellByColumn ( 0 , 'ContactName' ) ;
450
+ expect ( lastIndexCell . visibleColumnIndex ) . toEqual ( secondPinnedIndex ) ;
451
+
452
+ const headers = fix . debugElement . queryAll ( By . css ( COLUMN_HEADER_CLASS ) ) ;
453
+
454
+ expect ( headers [ headers . length - 2 ] . context . column . field ) . toEqual ( 'CompanyName' ) ;
455
+
456
+ expect ( headers [ headers . length - 1 ] . context . column . field ) . toEqual ( 'ContactName' ) ;
457
+ // expect(headers[secondPinnedIndex].parent.nativeElement.classList.contains(FIXED_HEADER_CSS)).toBe(true);
458
+
459
+ // verify container widths
460
+ expect ( grid . pinnedWidth ) . toEqual ( 400 ) ;
461
+ expect ( grid . unpinnedWidth + grid . scrollWidth ) . toEqual ( 400 ) ;
462
+ } ) ) ;
463
+ } ) ;
464
+
415
465
/* tslint:disable */
416
466
const companyData = [
417
467
{ "ID" : "ALFKI" , "CompanyName" : "Alfreds Futterkiste" , "ContactName" : "Maria Anders" , "ContactTitle" : "Sales Representative" , "Address" : "Obere Str. 57" , "City" : "Berlin" , "Region" : null , "PostalCode" : "12209" , "Country" : "Germany" , "Phone" : "030-0074321" , "Fax" : "030-0076545" } ,
@@ -745,3 +795,37 @@ export class GridInitialPinningComponent {
745
795
@ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
746
796
public instance : IgxGridComponent ;
747
797
}
798
+
799
+ @Component ( {
800
+ template : `
801
+ <igx-grid
802
+ [pinning]='pinningConfig'
803
+ [width]='"800px"'
804
+ [height]='"300px"'
805
+ [data]="data"
806
+ (onColumnInit)="initColumns($event)"
807
+ (onSelection)="cellSelected($event)"
808
+ [autoGenerate]="true">
809
+ </igx-grid>
810
+ `
811
+ } )
812
+ export class GridRightPinningComponent {
813
+ public selectedCell ;
814
+
815
+ public data = companyData ;
816
+ public pinningConfig : IPinningConfig = { columns : ColumnPinningPosition . End } ;
817
+
818
+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
819
+ public instance : IgxGridComponent ;
820
+
821
+ public initColumns ( column : IgxColumnComponent ) {
822
+ if ( column . field === 'CompanyName' || column . field === 'ContactName' ) {
823
+ column . pinned = true ;
824
+ }
825
+ column . width = '200px' ;
826
+ }
827
+
828
+ public cellSelected ( event : IGridCellEventArgs ) {
829
+ this . selectedCell = event . cell ;
830
+ }
831
+ }
0 commit comments