Sarveshgithub / sfdc-lwc-lightning-datatable

Salesforce Lighting Data table
MIT License
78 stars 28 forks source link

[ BUG ] - When a user specifies the Id the component has an error #152

Closed mickaelgudin closed 1 year ago

mickaelgudin commented 1 year ago

Describe the bug When we set Id field in the prop api names there is an error (because the Id field is already retrieved by defautl)

Expected behavior

update documentation to specify not to include Id in columns since retrieved by default (otherwise users will get this error not knowing why).

Sarveshgithub commented 1 year ago

fixed @mickaelgudin can you test ?

mickaelgudin commented 1 year ago

The idea is great, I thought of it right after reporting this issue, you did great @Sarveshgithub.

However, they were issues :

Here's the correction I made, I tested every scenario(only one field, every Id cases), it works great

    //remove id field if set
    let tempFields = new Set(cmp.fields.replace(/\s/g, '').split(','));
    ['id', 'Id', 'iD', 'ID'].forEach(idFieldCase => {
        if (tempFields.has(idFieldCase)) {
            tempFields.delete(idFieldCase);
        }
    });
    cmp.fields = Array.from(tempFields).join(',');