0

How can I add records to a lwc data table based on input, for example, I have a search input text on my component that looks for a custom object, and I need to add that specific custom object record to the data-table once the record is selected on the search input, how can I accomplish this considering that I already know what are the columns that I need to display on the table?

1
  • Please let me know if I need to provide more information about my question.
    – peepoCode
    Commented Dec 22, 2020 at 0:27

1 Answer 1

0

Q: Are your searched SObjects same SObject or not?

If you are searching the same SObject with different records, when you select a record, add your selected record's data to your data array.

Since you already know how data-table works. I will give you a simple code example:

columns = [
{ label: 'Id', fieldName: 'Id', type: 'text'},
{ label: 'Name', fieldName: 'Name', type: 'text'}
]
@track
records = [
{Id: 1, Name: record1}
]
// your input onchange event handler
onChange(e) {
  var input = e.detail.value
  // an @AuraEnable method in your apex
  getRecordInfo({inputInfo: input}).then(result => {
    // in your apex method you should return a SObject type
    this.records.push(result)
  }.catch(error => {
    console.log(error)
  })
  )
}

If your SObjects are in diffent types, you should make sure their fields' names are the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .