@@ -90,11 +90,12 @@ abstract class AreaItem {
9090 return this . component . option . apply ( this . component , arguments ) ;
9191 }
9292
93- _getRowElement ( index ) {
94- const that = this ;
95- if ( that . _tableElement && that . _tableElement . length > 0 ) {
96- return that . _tableElement [ 0 ] . rows [ index ] ;
93+ _getRowElement ( index : number ) : HTMLTableRowElement | null {
94+ if ( this . _tableElement ?. length > 0 ) {
95+ const tableElement = this . _tableElement . get ( 0 ) as HTMLTableElement ;
96+ return tableElement . rows [ index ] ;
9797 }
98+
9899 return null ;
99100 }
100101
@@ -139,57 +140,48 @@ abstract class AreaItem {
139140 }
140141
141142 _renderTableContent ( tableElement , data ) {
142- const that = this ;
143143 const rowsCount = data . length ;
144- let row ;
145- let cell ;
146- let i ;
147- let j ;
148- let rowElement ;
149- let cellElement ;
150- let cellText ;
151- const rtlEnabled = that . option ( 'rtlEnabled' ) ;
152- const encodeHtml = that . option ( 'encodeHtml' ) ;
153- let rowClassNames ;
144+ const rtlEnabled = this . option ( 'rtlEnabled' ) ;
145+ const encodeHtml = this . option ( 'encodeHtml' ) ;
154146
155- tableElement . data ( 'area' , that . _getAreaName ( ) ) ;
147+ tableElement . data ( 'area' , this . _getAreaName ( ) ) ;
156148 tableElement . data ( 'data' , data ) ;
157-
158149 tableElement . css ( 'width' , '' ) ;
159150
160151 const tbody = this . _getMainElementMarkup ( ) ;
161152
162- for ( i = 0 ; i < rowsCount ; i += 1 ) {
163- row = data [ i ] ;
164- rowClassNames = [ ] ;
153+ for ( let i = 0 ; i < rowsCount ; i += 1 ) {
154+ const row = data [ i ] ;
155+ const rowClassNames = [ ] ;
165156
166157 const tr = domAdapter . createElement ( 'tr' ) ;
167158
168- for ( j = 0 ; j < row . length ; j += 1 ) {
169- cell = row [ j ] ;
159+ for ( let j = 0 ; j < row . length ; j += 1 ) {
160+ const cell = row [ j ] ;
161+ const td = domAdapter . createElement ( 'td' ) ;
170162
171163 this . _getRowClassNames ( i , cell , rowClassNames ) ;
172164
173- const td = domAdapter . createElement ( 'td' ) ;
165+ let cellText = '' ;
174166
175167 if ( cell ) {
176168 cell . rowspan && td . setAttribute ( 'rowspan' , cell . rowspan || 1 ) ;
177169 cell . colspan && td . setAttribute ( 'colspan' , cell . colspan || 1 ) ;
178170
179171 const styleOptions = {
180- cellElement,
172+ cellElement : undefined ,
181173 cell,
182174 cellsCount : row . length ,
183175 cellIndex : j ,
184- rowElement,
176+ rowElement : undefined ,
185177 rowIndex : i ,
186178 rowsCount,
187179 rtlEnabled,
188180 classArray : [ ] ,
189181 cssArray : [ ] ,
190182 } ;
191183
192- that . _applyCustomStyles ( styleOptions ) ;
184+ this . _applyCustomStyles ( styleOptions ) ;
193185
194186 if ( styleOptions . cssArray . length ) {
195187 setStyle ( td , styleOptions . cssArray . join ( ';' ) ) ;
@@ -209,8 +201,6 @@ abstract class AreaItem {
209201 }
210202
211203 cellText = this . _getCellText ( cell , encodeHtml ) ;
212- } else {
213- cellText = '' ;
214204 }
215205
216206 const span = domAdapter . createElement ( 'span' ) ;
@@ -284,24 +274,15 @@ abstract class AreaItem {
284274 }
285275 }
286276
287- _getRowHeight ( index ) {
277+ _getRowHeight ( index : number ) : number {
288278 const row = this . _getRowElement ( index ) ;
289- let height = 0 ;
290-
291- const { offsetHeight } = row ;
292279
293- if ( row && row . lastChild ) {
294- if ( row . getBoundingClientRect ) {
295- const clientRect = getBoundingRect ( row ) ;
296- height = clientRect . height ;
297-
298- if ( height <= offsetHeight - 1 ) {
299- height = offsetHeight ;
300- }
301- }
280+ if ( row ?. lastChild ) {
281+ const { height } = row . getBoundingClientRect ( ) ;
302282
303- return height > 0 ? height : offsetHeight ;
283+ return height <= row . offsetHeight - 1 ? row . offsetHeight : height ;
304284 }
285+
305286 return 0 ;
306287 }
307288
@@ -345,69 +326,61 @@ abstract class AreaItem {
345326 this . _tableElement [ 0 ] . style . height = `${ totalHeight } px` ;
346327 }
347328
348- getColumnsWidth ( ) {
329+ getColumnsWidth ( ) : number [ ] {
349330 const rowsLength = this . getRowsLength ( ) ;
350- let rowIndex ;
351- let row ;
352- let i ;
353- let columnIndex ;
354- const processedCells = [ ] ;
355- const result = [ ] ;
356- const fillCells = function ( cells , rowIndex , columnIndex , rowSpan , colSpan ) {
357- let rowOffset ;
358- let columnOffset ;
359- for ( rowOffset = 0 ; rowOffset < rowSpan ; rowOffset += 1 ) {
360- for ( columnOffset = 0 ; columnOffset < colSpan ; columnOffset += 1 ) {
361- cells [ rowIndex + rowOffset ] = cells [ rowIndex + rowOffset ] || [ ] ;
362- cells [ rowIndex + rowOffset ] [ columnIndex + columnOffset ] = true ;
363- }
364- }
365- } ;
331+ const processedCells : boolean [ ] [ ] = [ ] ;
332+ const result : number [ ] = [ ] ;
366333
367- if ( rowsLength ) {
368- for ( rowIndex = 0 ; rowIndex < rowsLength ; rowIndex += 1 ) {
369- processedCells [ rowIndex ] = processedCells [ rowIndex ] || [ ] ;
370- row = this . _getRowElement ( rowIndex ) ;
371- for ( i = 0 ; i < row . cells . length ; i += 1 ) {
372- for ( columnIndex = 0 ; processedCells [ rowIndex ] [ columnIndex ] ; columnIndex += 1 ) ;
373- fillCells (
374- processedCells ,
375- rowIndex ,
376- columnIndex ,
377- row . cells [ i ] . rowSpan ,
378- row . cells [ i ] . colSpan ,
379- ) ;
380- if ( row . cells [ i ] . colSpan === 1 ) {
381- result [ columnIndex ] = result [ columnIndex ] || getRealElementWidth ( row . cells [ i ] ) ;
334+ if ( ! rowsLength ) {
335+ return [ ] ;
336+ }
337+
338+ for ( let rowIndex = 0 ; rowIndex < rowsLength ; rowIndex += 1 ) {
339+ processedCells [ rowIndex ] ||= [ ] ;
340+ const row = this . _getRowElement ( rowIndex ) as HTMLTableRowElement ;
341+
342+ Array . from ( row . cells ) . forEach ( ( cell ) => {
343+ let columnIndex = 0 ;
344+ for ( ; processedCells [ rowIndex ] [ columnIndex ] ; columnIndex += 1 ) ;
345+
346+ for ( let rowOffset = 0 ; rowOffset < cell . rowSpan ; rowOffset += 1 ) {
347+ for ( let columnOffset = 0 ; columnOffset < cell . colSpan ; columnOffset += 1 ) {
348+ processedCells [ rowIndex + rowOffset ] ||= [ ] ;
349+ processedCells [ rowIndex + rowOffset ] [ columnIndex + columnOffset ] = true ;
382350 }
383351 }
384- }
352+
353+ if ( cell . colSpan === 1 ) {
354+ result [ columnIndex ] ||= getRealElementWidth ( cell ) ;
355+ }
356+ } ) ;
385357 }
358+
386359 return result ;
387360 }
388361
389- setColumnsWidth ( values ) {
390- let i ;
391- const tableElement = this . _tableElement [ 0 ] ;
392- this . _colgroupElement . html ( '' ) ;
362+ setColumnsWidth ( values : number [ ] ) : void {
363+ const tableElement = this . _tableElement . get ( 0 ) ;
393364 const columnsCount = this . getColumnsCount ( ) ;
394- const columnWidth : any = [ ] ;
365+ const columnWidth : number [ ] = [ ] ;
395366
396- for ( i = 0 ; i < columnsCount ; i += 1 ) {
367+ for ( let i = 0 ; i < columnsCount ; i += 1 ) {
397368 columnWidth . push ( values [ i ] || 0 ) ;
398369 }
399370
400- for ( i = columnsCount ; i < values . length && values ; i += 1 ) {
371+ for ( let i = columnsCount ; i < values . length && values ; i += 1 ) {
401372 columnWidth [ columnsCount - 1 ] += values [ i ] ;
402373 }
403374
404- for ( i = 0 ; i < columnsCount ; i += 1 ) {
375+ this . _colgroupElement . html ( '' ) ;
376+
377+ for ( let i = 0 ; i < columnsCount ; i += 1 ) {
405378 const col = domAdapter . createElement ( 'col' ) ;
406379 col . style . width = `${ columnWidth [ i ] } px` ;
407380 this . _colgroupElement . append ( col ) ;
408381 }
409- this . _tableWidth = columnWidth . reduce ( ( sum , width ) => sum + width , 0 ) ;
410382
383+ this . _tableWidth = columnWidth . reduce ( ( sum , width ) => sum + width , 0 ) ;
411384 tableElement . style . width = `${ this . _tableWidth } px` ;
412385 tableElement . style . tableLayout = 'fixed' ;
413386 }
0 commit comments