@@ -13,6 +13,7 @@ import { GridFunctions } from '../../test-utils/grid-functions.spec';
13
13
import { SortingDirection } from '../../data-operations/sorting-expression.interface' ;
14
14
import { IgxGridTransaction } from '../tree-grid' ;
15
15
import { IgxTransactionService } from '../../services' ;
16
+ import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition' ;
16
17
17
18
describe ( 'Row Pinning #grid' , ( ) => {
18
19
const FIXED_ROW_CONTAINER = '.igx-grid__tr--pinned ' ;
@@ -226,7 +227,20 @@ describe('Row Pinning #grid', () => {
226
227
expect ( grid . getRowByIndex ( 1 ) . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
227
228
} ) ;
228
229
230
+ it ( 'should allow pinning onInit' , ( ) => {
231
+ expect ( ( ) => {
232
+ fix = TestBed . createComponent ( GridRowPinningComponent ) ;
233
+ grid = fix . componentInstance . instance ;
234
+ grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
235
+ fix . detectChanges ( ) ;
236
+ } ) . not . toThrow ( ) ;
237
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
238
+ expect ( grid . getRowByIndex ( 0 ) . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
239
+ } ) ;
240
+
229
241
it ( 'should pin rows when columns are grouped.' , ( ) => {
242
+ grid . height = '550px' ;
243
+ fix . detectChanges ( ) ;
230
244
// pin 1st and 2nd data row
231
245
grid . pinRow ( fix . componentInstance . data [ 0 ] ) ;
232
246
grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
@@ -258,6 +272,68 @@ describe('Row Pinning #grid', () => {
258
272
expect ( groupRows [ 0 ] . groupRow . records [ 0 ] . ID ) . toEqual ( 'BLAUS' ) ;
259
273
} ) ;
260
274
275
+ it ( 'should apply filtering to both pinned and unpinned rows.' , ( ) => {
276
+ grid . getRowByIndex ( 1 ) . pin ( ) ;
277
+ fix . detectChanges ( ) ;
278
+ grid . getRowByIndex ( 5 ) . pin ( ) ;
279
+ fix . detectChanges ( ) ;
280
+
281
+ let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
282
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 2 ) ;
283
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
284
+ expect ( pinRowContainer [ 0 ] . children [ 1 ] . context . rowID ) . toBe ( fix . componentInstance . data [ 5 ] ) ;
285
+
286
+ grid . filter ( 'ID' , 'B' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) , false ) ;
287
+ fix . detectChanges ( ) ;
288
+
289
+ pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
290
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
291
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( fix . componentInstance . data [ 5 ] ) ;
292
+ } ) ;
293
+
294
+ it ( 'should remove pinned container and recalculate sizes when all pinned records are filtered out.' , ( ) => {
295
+ grid . getRowByIndex ( 1 ) . pin ( ) ;
296
+ fix . detectChanges ( ) ;
297
+ let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
298
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
299
+
300
+ let expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
301
+ expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
302
+
303
+ grid . filter ( 'ID' , 'B' , IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' ) , false ) ;
304
+ fix . detectChanges ( ) ;
305
+
306
+ pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
307
+ expect ( pinRowContainer . length ) . toBe ( 0 ) ;
308
+
309
+ expect ( grid . pinnedRowHeight ) . toBe ( 0 ) ;
310
+ expectedHeight = parseInt ( grid . height , 10 ) - grid . pinnedRowHeight - 18 - grid . theadRow . nativeElement . offsetHeight ;
311
+ expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
312
+ } ) ;
313
+
314
+ it ( 'should return correct filterData collection.' , ( ) => {
315
+ grid . getRowByIndex ( 1 ) . pin ( ) ;
316
+ fix . detectChanges ( ) ;
317
+ grid . getRowByIndex ( 5 ) . pin ( ) ;
318
+ fix . detectChanges ( ) ;
319
+
320
+ grid . filter ( 'ID' , 'B' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) , false ) ;
321
+ fix . detectChanges ( ) ;
322
+
323
+ let gridFilterData = grid . filteredData ;
324
+ expect ( gridFilterData . length ) . toBe ( 7 ) ;
325
+ expect ( gridFilterData [ 0 ] . ID ) . toBe ( 'BLAUS' ) ;
326
+ expect ( gridFilterData [ 1 ] . ID ) . toBe ( 'BERGS' ) ;
327
+
328
+ fix . componentInstance . pinningConfig = { columns : ColumnPinningPosition . Start , rows : RowPinningPosition . Bottom } ;
329
+ fix . detectChanges ( ) ;
330
+
331
+ gridFilterData = grid . filteredData ;
332
+ expect ( gridFilterData . length ) . toBe ( 7 ) ;
333
+ expect ( gridFilterData [ 0 ] . ID ) . toBe ( 'BLAUS' ) ;
334
+ expect ( gridFilterData [ 1 ] . ID ) . toBe ( 'BERGS' ) ;
335
+ } ) ;
336
+
261
337
it ( 'should apply sorting to both pinned and unpinned rows.' , ( ) => {
262
338
grid . getRowByIndex ( 1 ) . pin ( ) ;
263
339
grid . getRowByIndex ( 5 ) . pin ( ) ;
@@ -482,6 +558,7 @@ describe('Row Pinning #grid', () => {
482
558
@Component ( {
483
559
template : `
484
560
<igx-grid
561
+ [allowFiltering]='true'
485
562
[pinning]='pinningConfig'
486
563
[width]='"800px"'
487
564
[height]='"500px"'
0 commit comments