From 7bae3b330b1965234c0bf7ca5d42e1d7b85086fd Mon Sep 17 00:00:00 2001 From: Arnold Zhou Date: Fri, 17 May 2024 09:46:56 +1000 Subject: [PATCH] feat: implement #36 --- src/elements/controls/listview.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/elements/controls/listview.ts b/src/elements/controls/listview.ts index 8c04eed..8972638 100644 --- a/src/elements/controls/listview.ts +++ b/src/elements/controls/listview.ts @@ -1,4 +1,5 @@ import { Bindable } from "@src/bindings/bindable"; +import { TwoWayBindable } from "@src/bindings/twoway/twowayBindable"; import { Axis } from "@src/positional/axis"; import { parseScaleOrFallback } from "@src/positional/parsing/parseScale"; import { Parsed } from "@src/positional/parsing/parsed"; @@ -83,6 +84,12 @@ export interface ListViewParams extends ElementParams */ canSelect?: boolean; + /** + * Whether a specific cell is selected in the listview. + * @default undefined + */ + selectedCell?: TwoWayBindable; + /** * Whether the rows are displayed in alternating darkness to make each row easier to see. * @default false @@ -124,6 +131,7 @@ class ListViewControl extends Control implements ListV items?: string[] | ListViewItem[]; scrollbars?: ScrollbarType; canSelect?: boolean; + selectedCell?: RowColumn; isStriped?: boolean; onHighlight?: (item: number, column: number) => void; onClick?: (item: number, column: number) => void; @@ -138,6 +146,12 @@ class ListViewControl extends Control implements ListV const binder = output.binder; binder.add(this, "items", params.items); + binder.twoway(this, "selectedCell", "onClick", params.selectedCell, (position: RowColumn) => { + if (this.onClick) + { + this.onClick(position.row, position.column); + } + }); this.showColumnHeaders = (!isUndefined(params.columns)); this.scrollbars = params.scrollbars;