Skip to content

Commit

Permalink
feat: implement #36
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmagic2020 committed May 16, 2024
1 parent 74ebec3 commit 7bae3b3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/elements/controls/listview.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -83,6 +84,12 @@ export interface ListViewParams extends ElementParams
*/
canSelect?: boolean;

/**
* Whether a specific cell is selected in the listview.
* @default undefined
*/
selectedCell?: TwoWayBindable<RowColumn>;

/**
* Whether the rows are displayed in alternating darkness to make each row easier to see.
* @default false
Expand Down Expand Up @@ -124,6 +131,7 @@ class ListViewControl<I, P> extends Control<ListViewDesc, I, P> 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;
Expand All @@ -138,6 +146,12 @@ class ListViewControl<I, P> extends Control<ListViewDesc, I, P> 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;
Expand Down

0 comments on commit 7bae3b3

Please sign in to comment.