Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selections in Tables #215

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/components/templates/ListView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ListView extends BridgeBase {
rowID: any;
response: any;
compositeKeys: any;
selectedValues: any;
constructor() {
// Note: BridgeBase constructor has 2 optional args:
// 1st: inDebug - sets this.bLogging: false if not provided
Expand Down Expand Up @@ -110,6 +111,9 @@ class ListView extends BridgeBase {
this.compositeKeys = theConfigProps?.compositeKeys;
this.rowID = this.compositeKeys && this.compositeKeys?.length === 1 ? this.compositeKeys[0] : defRowID;

this.selectedValue = theConfigProps.value;
this.selectedValues = theConfigProps.readonlyContextList;

// const componentConfig = this.thePConn.getRawMetadata().config;
// const refList = theConfigProps.referenceList;
this.searchIcon = Utils.getImageSrc('search', Utils.getSDKStaticContentUrl());
Expand Down Expand Up @@ -353,13 +357,15 @@ class ListView extends BridgeBase {
}

private radioRender: GridColumnBodyLitRenderer<any> = row => {
const rowID = row[this.rowID];
return html`<input name="radio-buttons" type="radio" .value="${rowID}" @change="${this.onRadioChange}" />`;
const rowValue = row[this.rowID];
const isRowSelected = rowValue === this.selectedValue;
return html`<input name="radio-buttons" type="radio" .value="${rowValue}" ?checked=${isRowSelected} @change="${this.onRadioChange}" />`;
};

private checkboxRender: GridColumnBodyLitRenderer<any> = row => {
const rowID = row[this.rowID];
return html`<input name="checkbox" type="checkbox" .value="${rowID}" @change="${this.onCheckboxClick}" />`;
const rowValue = row[this.rowID];
const isRowSelected = this.selectedValues.some(selectedValue => selectedValue[this.rowID] === rowValue);
return html`<input name="checkbox" type="checkbox" .value="${rowValue}" ?checked=${isRowSelected} @change="${this.onCheckboxClick}" />`;
};

onRadioChange(event) {
Expand Down
Loading