@@ -284,15 +284,21 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
284284 * how the table is renderer a second time, we now clone that list into a
285285 * local variable and only use the clone.
286286 */
287- localColumns : CdTableColumn [ ] ;
287+ set localColumns ( value : CdTableColumn [ ] ) {
288+ this . _localColumns = this . getTableColumnsWithNames ( value ) ;
289+ }
290+
291+ get localColumns ( ) : CdTableColumn [ ] {
292+ return this . _localColumns ;
293+ }
294+
295+ private _localColumns : CdTableColumn [ ] ;
288296
289297 model : TableModel = new TableModel ( ) ;
290298
291299 set tableColumns ( value : CdTableColumn [ ] ) {
292300 // In case a name is not provided set it to the prop name if present or an empty string
293- const valuesWithNames = value . map ( ( col : CdTableColumn ) =>
294- col ?. name ? col : { ...col , name : col ?. prop ? _ . capitalize ( _ . toString ( col . prop ) ) : '' }
295- ) ;
301+ const valuesWithNames = this . getTableColumnsWithNames ( value ) ;
296302 this . _tableColumns = valuesWithNames ;
297303 this . _tableHeaders . next ( valuesWithNames ) ;
298304 }
@@ -307,6 +313,18 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
307313 return this . localColumns ?. filter ?.( ( x ) => ! x . isHidden ) ;
308314 }
309315
316+ getTableColumnsWithNames ( value : CdTableColumn [ ] ) : CdTableColumn [ ] {
317+ return value . map ( ( col : CdTableColumn ) =>
318+ col ?. name ? col : { ...col , name : col ?. prop ? this . deCamelCase ( String ( col ?. prop ) ) : '' }
319+ ) ;
320+ }
321+
322+ deCamelCase ( str : string ) : string {
323+ return str
324+ . replace ( / ( [ A - Z ] ) / g, ( match ) => ` ${ match } ` )
325+ . replace ( / ^ ./ , ( match ) => match . toUpperCase ( ) ) ;
326+ }
327+
310328 icons = Icons ;
311329 cellTemplates : {
312330 [ key : string ] : TemplateRef < any > ;
0 commit comments