11import { clsName } from "../util" ;
2+ import { store } from "../util/store" ;
23import { COMPS_NAME , COLUMN_TYPES } from "../util/constant" ;
34import emitter from "../../../src/mixins/emitter" ;
45
@@ -58,58 +59,56 @@ export default {
5859 currentRowKey ( ) {
5960 return this . rowData [ this . rowKeyFieldName ] ;
6061 } ,
61- // expand row class
62- expanRowClass ( ) {
63- let result = {
64- [ clsName ( "expand-tr" ) ] : true
65- } ;
62+ // is row expanded
63+ isRowExpanded ( ) {
64+ let result = false ;
6665
6766 const { expandOption, expandedRowkeys, currentRowKey } = this ;
6867
6968 // defalut expand all rows
7069 if ( expandOption . defaultExpandAllRows ) {
71- result [ clsName ( "expand-tr-show" ) ] = true ;
70+ result = true ;
7271 }
7372 // defaultExpandedRowKeys includes currentRowKey
7473 else if ( expandedRowkeys . includes ( currentRowKey ) ) {
75- result [ clsName ( "expand-tr-show" ) ] = true ;
74+ result = true ;
7675 }
7776
7877 return result ;
7978 } ,
79+ // expand row class
80+ expanRowClass ( ) {
81+ let result = {
82+ [ clsName ( "expand-tr" ) ] : true ,
83+ [ clsName ( "expand-tr-show" ) ] : this . isRowExpanded
84+ } ;
85+ return result ;
86+ } ,
8087
8188 // is last left fixed column
82- lastLeftFixedColumn ( ) {
83- let result = null ;
84-
85- const fixedLeftColumns = this . colgroups . filter (
86- x => x . fixed === "left"
87- ) ;
88-
89- if ( fixedLeftColumns . length > 0 ) {
90- result = fixedLeftColumns [ fixedLeftColumns . length - 1 ] . field ;
91- }
92-
93- return result ;
89+ hasLeftFixedColumn ( ) {
90+ return this . colgroups . some ( x => x . fixed === "left" ) ;
9491 } ,
9592
96- // expand td class
97- expandTdClass ( ) {
98- let result = {
99- [ clsName ( "expand-td" ) ] : true
100- } ;
93+ // expand td content style
94+ expandTdContentStyle ( ) {
95+ let result = { } ;
10196
102- if ( this . lastLeftFixedColumn ) {
103- result [ clsName ( "fixed-left" ) ] = true ;
97+ if ( this . hasLeftFixedColumn ) {
98+ // table width
99+ if ( store . tableViewportWidth ) {
100+ result [ "width" ] = store . tableViewportWidth + "px" ;
101+ }
104102 }
103+
105104 return result ;
106105 }
107106 } ,
108107 methods : {
109- // 获取展开行的内容
108+ // get expande row content
110109 getExpandRowContent ( h ) {
111110 const { expandOption } = this ;
112- return (
111+ let result =
113112 expandOption . render &&
114113 expandOption . render (
115114 {
@@ -118,27 +117,37 @@ export default {
118117 rowIndex : this . rowIndex
119118 } ,
120119 h
121- )
122- ) ;
120+ ) ;
121+
122+ return result ;
123123 }
124124 } ,
125125 render ( h ) {
126126 const {
127+ isRowExpanded,
127128 columnCount,
128129 getExpandRowContent,
129130 expanRowStyle,
130131 expandTdClass
131132 } = this ;
132133
133- let content = getExpandRowContent ( h ) ;
134+ let result = null ;
134135
135- let result = (
136- < tr class = { this . expanRowClass } >
137- < td class = { expandTdClass } colSpan = { columnCount } >
138- { content }
139- </ td >
140- </ tr >
141- ) ;
136+ if ( isRowExpanded ) {
137+ let content = getExpandRowContent ( h ) ;
138+ result = (
139+ < tr class = { this . expanRowClass } >
140+ < td class = { clsName ( "expand-td" ) } colSpan = { columnCount } >
141+ < div
142+ class = { clsName ( "expand-td-content" ) }
143+ style = { this . expandTdContentStyle }
144+ >
145+ { content }
146+ </ div >
147+ </ td >
148+ </ tr >
149+ ) ;
150+ }
142151
143152 return result ;
144153 }
0 commit comments