use crate::prelude::*;
use crate::props::{FilterFn, IntoTextFilterFn, TextFilterFn};
-use crate::state::{DataStore, Selection, SelectionObserver};
+use crate::state::{DataStore, Selection};
use crate::widget::data_table::{DataTable, DataTableMouseEvent};
use crate::widget::{Column, Input, Row};
pub struct PwtGridPicker<S> {
filter: String,
store: S,
- _selection_observer: Option<SelectionObserver>,
_phantom: PhantomData<S>,
}
fn create(ctx: &Context<Self>) -> Self {
let props = ctx.props();
- let _selection_observer = match &props.selection {
- Some(selection) => Some(selection.add_listener({
- let on_select = props.on_select.clone();
- move |selection: Selection| {
- if let Some(on_select) = &on_select {
- if let Some(key) = selection.selected_key() {
- on_select.emit(key);
- }
- }
- }
- })),
- None => None,
- };
-
let mut me = Self {
- _selection_observer,
_phantom: PhantomData::<S>,
filter: String::new(),
store: props.table.get_store(),
fn view(&self, ctx: &Context<Self>) -> Html {
let props = ctx.props();
+ let on_select = ctx.props().on_select.clone();
let table: Html = props
.table
.clone()
.hover(true)
.header_focusable(false)
.selection(props.selection.clone())
- .on_row_click(|event: &mut DataTableMouseEvent| {
+ .on_row_click(move |event: &mut DataTableMouseEvent| {
let key = event.record_key.clone();
- if let Some(selection) = &event.selection {
- selection.select(key);
+ if let Some(on_select) = &on_select {
+ on_select.emit(key);
}
})
.into();