import { TableColumns } from './' ; param { Array } date function getColspanNum ( data = [ ] , num = 1 ) { let childs = [ ] ; for ( let i = 0 ; i < data . length ; i += 1 ) { if ( data [ i ] . children ) { childs = childs . concat ( data [ i ] . children || [ ] ) ; } } if ( childs && childs . length > 0 ) { num = getColspanNum ( childs , num + 1 ) ; } return num ; } param { Array } date function getRowspanNum ( data = [ ] , child = [ ] ) { let childs = [ ] ; for ( let i = 0 ; i < data . length ; i += 1 ) { if ( ! data [ i ] . children ) { childs . push ( data [ i ] ) ; } else if ( data [ i ] . children && data [ i ] . children ! . length > 0 ) { childs = childs . concat ( getRowspanNum ( data [ i ] . children , child ) ) ; } } return childs ; } export interface ILevelItems { header : TableColumns [ ] [ ] ; ellipsis ? : Record < string , boolean > ; render : { [ key ] : any ; } ; } param { Array } date export const getLevelItems = ( data , result ? ) : ILevelItems => { if ( ! result ) { result = { header : [ ] , render : { } } ; } if ( result && ! result . header ) { result . header = [ ] ; } if ( result && ! result . render ) { result . render = { } ; } let child = [ ] ; const levelTop = [ ] ; for ( let i = 0 ; i < data . length ; i += 1 ) { if ( data [ i ] . render && data [ i ] . key ) { result . render [ data [ i ] . key as string ] = data [ i ] . render ; } if ( data [ i ] . ellipsis && data [ i ] . key ) { if ( ! result . ellipsis ) result . ellipsis = { } ; result . ellipsis [ data [ i ] . key ! ] = true ; } if ( result . header . length === 0 ) { if ( data [ i ] . children && data [ i ] . children && data [ i ] . children ! . length > 0 ) { data [ i ] . colSpan = getRowspanNum ( data [ i ] . children as TableColumns [ ] ) . length ; } levelTop . push ( data [ i ] ) ; } if ( data [ i ] && data [ i ] . children ) { child = child . concat ( data [ i ] . children ! . map ( ( item ) => { if ( item . children && item . children . length > 0 ) { item . colSpan = getRowspanNum ( item . children ) . length ; } return item ; } ) ) ; } } if ( result . header . length === 0 ) { const num = getColspanNum ( levelTop ) ; result . header . push ( levelTop . map ( ( item ) => { if ( num === 1 ) return item ; if ( ! item . children || ( item . children && item . children . length === 0 ) ) { item . rowSpan = num ; } return item ; } ) ) ; } if ( child && child . length > 0 ) { const num = getColspanNum ( child ) ; result . header . push ( child . map ( ( item ) => { if ( num === 1 ) return item ; if ( ! item . children || ( item . children && item . children . length === 0 ) ) { item . rowSpan = num ; } return item ; } ) ) ; result = getLevelItems ( child , result ) ; } return result ; } ; param { Array } data export const getAllColumnsKeys = ( data , keys = [ ] ) : string [ ] => { for ( let i = 0 ; i < data . length ; i += 1 ) { if ( data [ i ] . children ) { keys = keys . concat ( getAllColumnsKeys ( data [ i ] . children || [ ] ) ) ; } else if ( data [ i ] . key ) { keys . push ( data [ i ] . key ) ; } } return keys ; } ;