-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreactiveTable.js
More file actions
41 lines (26 loc) · 928 Bytes
/
reactiveTable.js
File metadata and controls
41 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-disable no-console */
import { api, LightningElement, track } from 'lwc';
export default class ReactiveTable extends LightningElement {
@api viewable
@track data = []
@track columns = []
@api
get objects(){
return this.data
}
set objects(data){
if(!data){ return }
const [ record ] = data
const viewable = this.viewable.split(',').map(x => x.trim())
const fields = Object.keys(record).filter(x => viewable.includes(x))
const columns = fields.map(x => ({ label: this.labeler(x), fieldName: x }))
//console.dir( 'ReactiveTable.set.object data => ' )
//console.dir( JSON.parse( JSON.stringify( {viewable} ) ) )
this.columns = columns
this.data = data
}
labeler(raw){
const s = raw.replace('__c', '').replace(/_/gi, ' ')
return s
}
}