admin管理员组文章数量:1122832
I am trying to automatically select(checkbox) the nested rows when selecting the parent row in a lightning-tree-grid.
It's my understanding that the selected-rows attribute on the lightning-tree-grid might be able to do this. I can't figure out if what I am doing is wrong, or I am not giving it what it needs to work. Ive included screenshots of 'most' of the code to help. I did find other supporting links that are related to my issue but I still cant get it to work.
lwc wire issue with select-rows
Selecte Children automatically when Select Parent
HTML
<div class="spinnerHolder">
<template if:true={isLoading}>
<lightning-spinner alternative-text="loading"></lightning-spinner>
</template>
<lightning-tree-grid
lwc:if={treeGridData.length}
class="results"
data-id="gridResult"
columns={gridColumns}
data={treeGridData}
key-field="contactName"
expanded-rows={expandedList}
selected-rows={selectedData}
onrowselection={selectRowHandler}
>
</lightning-tree-grid>
</div>
JS
@track selectedData = [];
selectRowHandler(event) {
let temp = [];
for (let i = 0; i < event.detail.selectedRows.length; i++) {
temp.push(event.detail.selectedRows[i]);
}
this.selectedData = temp;
console.log('selected Data', this.selectedData);
}
//probably dont need to show ALL of this but..
@wire(getResults, { filterString: '$bindFilters' })
contactsResult({ error, data }) {
this.gridisLoading = true;
this.contactsCount = 0;
this.offset = 0;
console.log(data);
if (data) {
const rawData = data;
this.contactsCount = rawData.length;
if (this.contactsCount === 0) {
this.gridisLoading = false;
this.activateSearch();
} else {
try {
this.initialData = dataHelper.transformDataObject(rawData);
this.downloadData = downloader.createCsvContent(rawData);
// console.log(this.downloadData);
if (this.missingPersons.length > 0) {
this.initialData = dataHelper.filterForMissingPerson(this.initialData, this.missingPersons);
this.downloadData = downloader.filterForMissingPersonDownload(this.downloadData, this.missingPersons);
}
this.sliceData();
} catch (e) {
this.handleError(e);
} finally {
this.gridisLoading = false;
this.activateSearch();
}
}
} else if (error) {
this.handleError(error);
}
this.gridisLoading = false;
this.activateSearch();
}
I am trying to automatically select(checkbox) the nested rows when selecting the parent row in a lightning-tree-grid.
It's my understanding that the selected-rows attribute on the lightning-tree-grid might be able to do this. I can't figure out if what I am doing is wrong, or I am not giving it what it needs to work. Ive included screenshots of 'most' of the code to help. I did find other supporting links that are related to my issue but I still cant get it to work.
lwc wire issue with select-rows
Selecte Children automatically when Select Parent
HTML
<div class="spinnerHolder">
<template if:true={isLoading}>
<lightning-spinner alternative-text="loading"></lightning-spinner>
</template>
<lightning-tree-grid
lwc:if={treeGridData.length}
class="results"
data-id="gridResult"
columns={gridColumns}
data={treeGridData}
key-field="contactName"
expanded-rows={expandedList}
selected-rows={selectedData}
onrowselection={selectRowHandler}
>
</lightning-tree-grid>
</div>
JS
@track selectedData = [];
selectRowHandler(event) {
let temp = [];
for (let i = 0; i < event.detail.selectedRows.length; i++) {
temp.push(event.detail.selectedRows[i]);
}
this.selectedData = temp;
console.log('selected Data', this.selectedData);
}
//probably dont need to show ALL of this but..
@wire(getResults, { filterString: '$bindFilters' })
contactsResult({ error, data }) {
this.gridisLoading = true;
this.contactsCount = 0;
this.offset = 0;
console.log(data);
if (data) {
const rawData = data;
this.contactsCount = rawData.length;
if (this.contactsCount === 0) {
this.gridisLoading = false;
this.activateSearch();
} else {
try {
this.initialData = dataHelper.transformDataObject(rawData);
this.downloadData = downloader.createCsvContent(rawData);
// console.log(this.downloadData);
if (this.missingPersons.length > 0) {
this.initialData = dataHelper.filterForMissingPerson(this.initialData, this.missingPersons);
this.downloadData = downloader.filterForMissingPersonDownload(this.downloadData, this.missingPersons);
}
this.sliceData();
} catch (e) {
this.handleError(e);
} finally {
this.gridisLoading = false;
this.activateSearch();
}
}
} else if (error) {
this.handleError(error);
}
this.gridisLoading = false;
this.activateSearch();
}
Share
Improve this question
asked Nov 21, 2024 at 14:25
lachelache
8303 gold badges20 silver badges36 bronze badges
1 Answer
Reset to default 0It ended up being my understanding of @track vs @api. @api exposes the variable and @track well, tracks changes. However every time $bindfilters changed it was clearing selectedData also, which didn't help. So a combination of my misunderstanding basically.
本文标签: checkboxlwc selectrows attribute wont update for tree gridStack Overflow
版权声明:本文标题:checkbox - lwc select-rows attribute wont update for tree grid? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310035a1934233.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论