buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-27 11:23:11
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-05-15 15:37:57
 */
import { LightningElement, track, api,wire } from 'lwc';
export default class LexDynamicTable extends LightningElement {
    @api columnList;
    @api title;
    @track columns;
    @track objectApiName;
    @track pickListvalues;
    @track rows = [{ uuid: this.createUUID()}];
    connectedCallback() {
        let cleanedColumnList = this.columnList[0] === '\\' ? this.columnList.substring(1) : this.columnList;
        if(cleanedColumnList)
        {
            this.columns = cleanedColumnList;
        }
    }
 
    createUUID() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
          });
    }
 
    @api
    retrieveRecords() {
        let rows = Array.from(this.template.querySelectorAll(".inputRows") );
        var records=[];
        rows.map(row => {
            let texts = Array.from(row.querySelectorAll(".fields"));
            if(texts)
            {
                var textVal=this.fieldValues(texts);
                records=[...records,textVal];
            }
        });
        return records;
    }
    fieldValues(cells)
    {
        return cells.reduce((record, cell) => {
            let inputVal = cell.inputValue();
            if(inputVal.value!=undefined)
            {
                record[inputVal.field] = inputVal.value;
            }
            return record;
        }, {});
    }
    removeRow(event) {
        const list = this.template.querySelectorAll(['lightning-button-icon']);
        if(list.length / 2 == 1){
            return;
        }
        this.rows.splice(event.target.value, 1);
    }
    
    addRow() {
        this.rows.push({ uuid: this.createUUID()});
    }
}