@@ -85,28 +85,54 @@ export default {
8585 const hasDetailsSlot = this . hasNormalizedSlot ( detailsSlotName )
8686 const formatted = this . getFormattedValue ( item , field )
8787 const key = field . key
88+ // We only uses the helper components for sticky columns to
89+ // improve performance of BTable/BTableLite by reducing the
90+ // total number of vue instances created during render
91+ const cellTag = field . stickyColumn
92+ ? field . isRowHeader
93+ ? BTh
94+ : BTd
95+ : field . isRowHeader
96+ ? 'th'
97+ : 'td'
98+ const cellVariant =
99+ item . _cellVariants && item . _cellVariants [ key ]
100+ ? item . _cellVariants [ key ]
101+ : field . variant || null
88102 const data = {
89103 // For the Vue key, we concatenate the column index and
90104 // field key (as field keys could be duplicated)
91105 // TODO: Although we do prevent duplicate field keys...
92106 // So we could change this to: `row-${rowIndex}-cell-${key}`
93107 key : `row-${ rowIndex } -cell-${ colIndex } -${ key } ` ,
94108 class : [ field . class ? field . class : '' , this . getTdValues ( item , key , field . tdClass , '' ) ] ,
95- props : {
96- stackedHeading : this . isStacked ? field . label : null ,
97- stickyColumn : field . stickyColumn ,
98- variant :
99- item . _cellVariants && item . _cellVariants [ key ]
100- ? item . _cellVariants [ key ]
101- : field . variant || null
102- } ,
109+ props : { } ,
103110 attrs : {
104111 'aria-colindex' : String ( colIndex + 1 ) ,
105112 ...( field . isRowHeader
106113 ? this . getThValues ( item , key , field . thAttr , 'row' , { } )
107114 : this . getTdValues ( item , key , field . tdAttr , { } ) )
108115 }
109116 }
117+ if ( field . stickyColumn ) {
118+ // We are using the helper BTd or BTh
119+ data . props = {
120+ stackedHeading : this . isStacked ? field . label : null ,
121+ stickyColumn : field . stickyColumn ,
122+ variant : cellVariant
123+ }
124+ } else {
125+ // Using native TD or TH element, so we need to
126+ // add in the attributes and variant class
127+ data . attrs [ 'data-label' ] =
128+ this . isStacked && ! isUndefinedOrNull ( field . label ) ? toString ( field . label ) : null
129+ data . attrs . role = field . isRowHeader ? 'rowheader' : 'cell'
130+ data . attrs . scope = field . isRowHeader ? 'row' : null
131+ // Add in the variant class
132+ if ( cellVariant ) {
133+ data . class . push ( `${ this . dark ? 'bg' : 'table' } -${ cellVariant } ` )
134+ }
135+ }
110136 const slotScope = {
111137 item : item ,
112138 index : rowIndex ,
@@ -135,7 +161,7 @@ export default {
135161 $childNodes = [ h ( 'div' , { } , [ $childNodes ] ) ]
136162 }
137163 // Render either a td or th cell
138- return h ( field . isRowHeader ? BTh : BTd , data , [ $childNodes ] )
164+ return h ( cellTag , data , [ $childNodes ] )
139165 } ,
140166 renderTbodyRow ( item , rowIndex ) {
141167 // Renders an item's row (or rows if details supported)
0 commit comments