1- import { CellMatrix , CellMatrixProps , StickyRanges } from './CellMatrix' ;
1+ import { CellMatrix , CellMatrixProps , StickyRanges , Span } from './CellMatrix' ;
22import { GridColumn , GridRow } from './InternalModel' ;
33import { Range } from './Range' ;
44
@@ -41,19 +41,18 @@ export class CellMatrixBuilder implements ICellMatrixBuilder {
4141 if ( ! Array . isArray ( this . cellMatrix . props . columns ) ) {
4242 throw new Error ( 'Feeded ReactGrids "columns" property is not an array!' )
4343 }
44- this . cellMatrix . rows = this . cellMatrix . props . rows . reduce (
44+ this . cellMatrix . rows = this . cellMatrix . props . rows . reduce < GridRow [ ] > (
4545 ( rows , row , idx ) => {
4646 const top = this . getTop ( idx , topStickyRows , rows ) ;
4747 const height = row . height || CellMatrix . DEFAULT_ROW_HEIGHT ;
4848 rows . push ( { ...row , top, height, idx, bottom : top + height } as GridRow ) ;
4949 this . cellMatrix . height += height ;
50- // TODO what with rowIndexLookup?
5150 this . cellMatrix . rowIndexLookup [ row . rowId ] = idx ;
5251 return rows ;
5352 } ,
54- [ ] as GridRow [ ]
53+ [ ]
5554 ) ;
56- this . cellMatrix . columns = this . cellMatrix . props . columns . reduce (
55+ this . cellMatrix . columns = this . cellMatrix . props . columns . reduce < GridColumn [ ] > (
5756 ( cols , column , idx ) => {
5857 const left = this . getLeft ( idx , leftStickyColumns , cols ) ;
5958 const width = column . width
@@ -65,11 +64,36 @@ export class CellMatrixBuilder implements ICellMatrixBuilder {
6564 this . cellMatrix . columnIndexLookup [ column . columnId ] = idx ;
6665 return cols ;
6766 } ,
68- [ ] as GridColumn [ ]
67+ [ ]
6968 ) ;
7069 return this ;
7170 }
7271
72+ setRangesToRenderLookup ( ) : CellMatrixBuilder {
73+ let rangesToExclude : Range [ ] = [ ] ;
74+ this . cellMatrix . rows . forEach ( ( row , idy ) => {
75+ row . cells . forEach ( ( cell , idx ) => {
76+ const { rowspan = 0 , colspan = 0 } = cell ;
77+ const rows = rowspan ? this . cellMatrix . rows . slice ( idy , idy + rowspan ) : [ this . cellMatrix . rows [ idy ] ] ;
78+ const columns = colspan ? this . cellMatrix . columns . slice ( idx , idx + colspan ) : [ this . cellMatrix . columns [ idx ] ] ;
79+ const range = new Range ( rows , columns )
80+ rangesToExclude = rangesToExclude . concat ( this . getRangesToRender ( range ) ) ;
81+ this . cellMatrix . spanCellLookup [ this . cellMatrix . getLocationToFindRangeByIds ( idx , idy ) ] = {
82+ range : range
83+ }
84+ } )
85+ } ) ;
86+ const keys = rangesToExclude . map ( range => `${ range . columns [ 0 ] . idx } , ${ range . rows [ 0 ] . idx } ` ) ;
87+ Object . keys ( this . cellMatrix . spanCellLookup ) . filter ( key => ! keys . includes ( key ) ) . forEach ( key => this . cellMatrix . rangesToRender [ key ] = this . cellMatrix . spanCellLookup [ key ] ) ;
88+ return this ;
89+ }
90+
91+ getRangesToRender ( range : Range ) : Range [ ] {
92+ const result = range . rows . flatMap ( row => range . columns . map ( column => new Range ( [ row ] , [ column ] ) ) ) ;
93+ result . shift ( ) ;
94+ return result ;
95+ }
96+
7397 fillSticky ( edges : StickyEdges = { leftStickyColumns : 0 , topStickyRows : 0 } ) : CellMatrixBuilder {
7498 const { leftStickyColumns, topStickyRows } = edges ;
7599 this . cellMatrix . ranges . stickyLeftRange = new Range ( this . cellMatrix . rows ,
0 commit comments