File tree Expand file tree Collapse file tree 4 files changed +109
-8
lines changed
Expand file tree Collapse file tree 4 files changed +109
-8
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,12 @@ function parseHeaderRows<RecordType>(
3535
3636 let colSpan : number = 1 ;
3737
38- if ( ( column as ColumnGroupType < RecordType > ) . children ) {
39- colSpan = fillRowCells (
40- ( column as ColumnGroupType < RecordType > ) . children ,
41- currentColIndex ,
42- rowIndex + 1 ,
43- ) . reduce ( ( total , count ) => total + count , 0 ) ;
38+ const subColumns = ( column as ColumnGroupType < RecordType > ) . children ;
39+ if ( subColumns && subColumns . length > 0 ) {
40+ colSpan = fillRowCells ( subColumns , currentColIndex , rowIndex + 1 ) . reduce (
41+ ( total , count ) => total + count ,
42+ 0 ,
43+ ) ;
4444 cell . hasSubColumns = true ;
4545 }
4646
Original file line number Diff line number Diff line change @@ -40,10 +40,11 @@ function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<R
4040 // Convert `fixed='true'` to `fixed='left'` instead
4141 const parsedFixed = fixed === true ? 'left' : fixed ;
4242
43- if ( ( column as ColumnGroupType < RecordType > ) . children ) {
43+ const subColumns = ( column as ColumnGroupType < RecordType > ) . children ;
44+ if ( subColumns && subColumns . length > 0 ) {
4445 return [
4546 ...list ,
46- ...flatColumns ( ( column as ColumnGroupType < RecordType > ) . children ) . map ( subColum => ( {
47+ ...flatColumns ( subColumns ) . map ( subColum => ( {
4748 fixed : parsedFixed ,
4849 ...subColum ,
4950 } ) ) ,
Original file line number Diff line number Diff line change @@ -38,6 +38,40 @@ describe('Table.Basic', () => {
3838 const wrapper = mount ( createTable ( { columns : [ ] } ) ) ;
3939 expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
4040 } ) ;
41+
42+ it ( 'column children undefined' , ( ) => {
43+ const wrapper = mount (
44+ createTable ( {
45+ columns : [
46+ {
47+ title : '姓名' ,
48+ dataIndex : 'name' ,
49+ key : 'name' ,
50+ children : [ ] ,
51+ } ,
52+ {
53+ title : '年龄' ,
54+ dataIndex : 'age' ,
55+ key : 'age' ,
56+ children : undefined ,
57+ } ,
58+ ] ,
59+ } ) ,
60+ ) ;
61+ expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
62+ expect (
63+ wrapper
64+ . find ( 'th' )
65+ . at ( 0 )
66+ . text ( ) ,
67+ ) . toEqual ( '姓名' ) ;
68+ expect (
69+ wrapper
70+ . find ( 'th' )
71+ . at ( 1 )
72+ . text ( ) ,
73+ ) . toEqual ( '年龄' ) ;
74+ } ) ;
4175 } ) ;
4276
4377 describe ( 'renders empty text correctly' , ( ) => {
Original file line number Diff line number Diff line change @@ -482,6 +482,72 @@ exports[`Table.Basic renders correctly basic 1`] = `
482482</div >
483483` ;
484484
485+ exports [` Table.Basic renders correctly column children undefined 1` ] = `
486+ <div
487+ class = " rc-table"
488+ >
489+ <div
490+ class = " rc-table-container"
491+ >
492+ <div
493+ class = " rc-table-content"
494+ >
495+ <table
496+ style = " table-layout: auto;"
497+ >
498+ <colgroup />
499+ <thead
500+ class = " rc-table-thead"
501+ >
502+ <tr >
503+ <th
504+ class = " rc-table-cell"
505+ >
506+ 姓名
507+ </th >
508+ <th
509+ class = " rc-table-cell"
510+ >
511+ 年龄
512+ </th >
513+ </tr >
514+ </thead >
515+ <tbody
516+ class = " rc-table-tbody"
517+ >
518+ <tr
519+ class = " rc-table-row rc-table-row-level-0"
520+ data-row-key = " key0"
521+ >
522+ <td
523+ class = " rc-table-cell"
524+ >
525+ Lucy
526+ </td >
527+ <td
528+ class = " rc-table-cell"
529+ />
530+ </tr >
531+ <tr
532+ class = " rc-table-row rc-table-row-level-0"
533+ data-row-key = " key1"
534+ >
535+ <td
536+ class = " rc-table-cell"
537+ >
538+ Jack
539+ </td >
540+ <td
541+ class = " rc-table-cell"
542+ />
543+ </tr >
544+ </tbody >
545+ </table >
546+ </div >
547+ </div >
548+ </div >
549+ ` ;
550+
485551exports [` Table.Basic renders correctly no columns 1` ] = `
486552<div
487553 class = " rc-table"
You can’t perform that action at this time.
0 commit comments