I am generating HTML table rows with data dynamically based on salesforce data from apex. Below is the structure.
<template for:each={Details} for:item="Detail">
<tr data-id={Detail.pbId} key={Detail.pbId}>
<td>
<input name={Detail.pbId} value={Detail.pbOrder} size="1"></input>
</td>
<td>
<lightning-button-icon id={Detail.pbId} icon-name="utility:delete" variant="bare" onclick={handleRemove}></lightning-button-icon>
</td>
</tr>
</template>
handleRemove(event){
var id = event.target.id;
var rowId = event.target.closest("tr").id;
alert(rowId +' '+ id);
// this.template.querySelectorAll(id).style="display:none";
// this.template.querySelectorAll(id).classList.add('hide');
// this.template.querySelector('.id').style="color:red";
// this.template.querySelectorAll('[id="' +id+ '"]').classList.add('hide');
// this.template.querySelectorAll('[id="' +id+ '"]').className = 'hide';
const theDiv = this.template.querySelector('[data-id="' +id+ '"]');
theDiv.className = 'hide';
}
.hide{
display: none;
}
I want to delete the row from the dom when delete button is clicked. In the JS you can see I have tried lot of things but none of them worked. Can anyone guide me towards the right way to hide in LWC JS Tried below link as well: Use template.querySelector with variable for selector?
Previously in Aura I have dome similar functionality using below line but it is not working in LWC. Or maybe I am doing something wrong.
document.getElementById(recordId).style.display = 'none';
isHiddenproperty to youDetailsitems in JS and then when you iterate use <template if:false={Detail.isHidden}>. But CSS classes can also work