import { TableList } from "lib/comps/list/TableList"; import { useLocal } from "lib/utils/use-local"; import { FC, ReactElement, useEffect, useRef } from "react"; import { BaseForm } from "../../base/BaseForm"; import { FMLocal } from "../../typings"; export const TableEdit: FC<{ on_init: () => FMLocal; name: string; child: any; PassProp: any; item: PrasiItem; bottom: any; body: any; }> = ({ on_init, name, child, PassProp, item, bottom, body }) => { const fm = on_init(); const local = useLocal( { tbl: null as any, }, () => {} ); const ref = useRef(null); if (!Array.isArray(fm.data[name])) { if (typeof fm.data[name] === "object") { fm.data[name] = [JSON.parse(JSON.stringify(fm.data[name]))]; } else { fm.data[name] = []; } } const value = fm.data[name]; return ( <>
.rdg { overflow-y: hidden !important; } .rdg-cell > div { flex-direction: row; align-items: center; padding-right: 5px; .field { flex: 1; padding-top: 0px; } } .field-error { display: none; } ` )} style={{ height: isEditor ? 100 : value.length === 0 ? 50 : value.length * 50 + 50, }} ref={ref} > {/* */} { local.tbl = tbl; local.render(); }} mode={"table"} _item={item} gen_fields={[]} row_click={({ event }) => { event.preventDefault(); event.stopPropagation(); }} selected={() => { return false; }} filter_name={""} render_col={(arg) => { const { props, tbl, child } = arg; const fm_row = { ...fm, render: local.render }; fm_row.data = props.row; local.tbl = tbl; const key = props.column.key; return ( {}, remove: () => { fm.data[name] = tbl.data.filter( (e: any) => e !== props.row ); fm.render(); }, add: () => { tbl.data.push({}); fm.render(); }, }} > {child} ); }} />
{ local.tbl.data.push({}); fm.render(); setTimeout(() => { const last = Array.from( ref.current?.querySelectorAll(".rdg-row") || [] ).pop(); const input = last?.querySelector("input"); if (input) { input.focus(); } }, 100); }, }} > {bottom}
); };