A few fixes
This commit is contained in:
@@ -14,6 +14,7 @@ import type { GridlerColumn } from '../Column';
|
||||
import { type GridlerProps, type GridlerState, useGridlerStore } from '../GridlerStore';
|
||||
|
||||
export function GlidlerFormAdaptor(props: {
|
||||
changeOnActiveClick?: boolean;
|
||||
descriptionField?: ((data: Record<string, unknown>) => string) | string;
|
||||
getMenuItems?: GridlerProps['getMenuItems'];
|
||||
onReload?: () => void;
|
||||
@@ -23,13 +24,36 @@ export function GlidlerFormAdaptor(props: {
|
||||
) => void;
|
||||
showDescriptionInMenu?: boolean;
|
||||
}) {
|
||||
const [getState, mounted, setState, reload] = useGridlerStore((s) => [
|
||||
const [getState, mounted, setState, reload, _events] = useGridlerStore((s) => [
|
||||
s.getState,
|
||||
s.mounted,
|
||||
s.setState,
|
||||
s.reload,
|
||||
s._events,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mounted && props.changeOnActiveClick) {
|
||||
const evf = (event: CustomEvent<any>) => {
|
||||
const { row, state } = event.detail;
|
||||
const getRowBuffer = state.getRowBuffer as (row: number) => Record<string, unknown>;
|
||||
if (getRowBuffer) {
|
||||
const rowData = getRowBuffer(row);
|
||||
if (!rowData) {
|
||||
return;
|
||||
}
|
||||
props.onRequestForm('change', rowData);
|
||||
}
|
||||
};
|
||||
_events?.addEventListener('onCellActivated', evf as any);
|
||||
return () => {
|
||||
if (evf) {
|
||||
_events?.removeEventListener('onCellActivated', evf as any);
|
||||
}
|
||||
};
|
||||
}
|
||||
}, [props.changeOnActiveClick, mounted, _events]);
|
||||
|
||||
const getMenuItems = useCallback(
|
||||
(
|
||||
id: string,
|
||||
|
||||
Reference in New Issue
Block a user