A few fixes

This commit is contained in:
Hein
2025-10-30 13:04:13 +02:00
parent 1284f46aa9
commit abf9433c10
8 changed files with 63 additions and 11 deletions

View File

@@ -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,