Search working

This commit is contained in:
Hein 2025-10-30 10:20:25 +02:00
parent bd47e9d0ab
commit 0943ffc483
3 changed files with 32 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { CompactSelection } from '@glideapps/glide-data-grid'; import { CompactSelection } from '@glideapps/glide-data-grid';
import { useDebouncedValue } from '@mantine/hooks';
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
import { useGridlerStore } from './GridlerStore'; import { useGridlerStore } from './GridlerStore';
@ -21,6 +22,7 @@ export const Computer = React.memo(() => {
ready, ready,
scrollToRowKey, scrollToRowKey,
searchStr,
selectedRowKey, selectedRowKey,
setState, setState,
setStateFN, setStateFN,
@ -39,6 +41,7 @@ export const Computer = React.memo(() => {
ready: s.ready, ready: s.ready,
scrollToRowKey: s.scrollToRowKey, scrollToRowKey: s.scrollToRowKey,
searchStr: s.searchStr,
selectedRowKey: s.selectedRowKey, selectedRowKey: s.selectedRowKey,
setState: s.setState, setState: s.setState,
setStateFN: s.setStateFN, setStateFN: s.setStateFN,
@ -46,6 +49,10 @@ export const Computer = React.memo(() => {
values: s.values, values: s.values,
})); }));
const debouncedSearchStr = useDebouncedValue(searchStr, 400, {
leading: true,
});
useEffect(() => { useEffect(() => {
const searchSelection = async () => { const searchSelection = async () => {
const page_data = getState('_page_data'); const page_data = getState('_page_data');
@ -161,6 +168,21 @@ export const Computer = React.memo(() => {
); );
}, [columns]); }, [columns]);
useEffect(() => {
if (debouncedSearchStr === undefined || debouncedSearchStr === null) {
return;
}
loadPage(0, 'all').then(() => {
getState('refreshCells')?.();
getState('_events')?.dispatchEvent?.(
new CustomEvent('onSearched', {
detail: { search: debouncedSearchStr },
})
);
});
}, [debouncedSearchStr]);
useEffect(() => { useEffect(() => {
if (!colSort) { if (!colSort) {
return; return;

View File

@ -76,7 +76,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
?.forEach((filter: any) => { ?.forEach((filter: any) => {
ops.push({ ops.push({
name: `${filter.id}`, name: `${filter.id}`,
op: filter.operator, op: 'contains',
type: 'searchor', type: 'searchor',
value: searchStr, value: searchStr,
}); });

View File

@ -17,6 +17,7 @@ export const GridlerGoAPIExampleEventlog = () => {
const [apiKey, setApiKey] = useLocalStorage({ defaultValue: '', key: 'apikey' }); const [apiKey, setApiKey] = useLocalStorage({ defaultValue: '', key: 'apikey' });
const [selectRow, setSelectRow] = useState<string | undefined>(''); const [selectRow, setSelectRow] = useState<string | undefined>('');
const [values, setValues] = useState<Array<Record<string, any>>>([]); const [values, setValues] = useState<Array<Record<string, any>>>([]);
const [search, setSearch] = useState<string>('');
const [sections, setSections] = useState<Record<string, unknown> | undefined>(undefined); const [sections, setSections] = useState<Record<string, unknown> | undefined>(undefined);
const columns: GridlerColumns = [ const columns: GridlerColumns = [
{ {
@ -110,6 +111,7 @@ export const GridlerGoAPIExampleEventlog = () => {
}} }}
ref={ref} ref={ref}
scrollToRowKey={selectRow ? parseInt(selectRow, 10) : undefined} scrollToRowKey={selectRow ? parseInt(selectRow, 10) : undefined}
searchStr={search}
sections={{ ...sections, rightElementDisabled: false }} sections={{ ...sections, rightElementDisabled: false }}
selectFirstRowOnMount={true} selectFirstRowOnMount={true}
selectMode="row" selectMode="row"
@ -131,6 +133,13 @@ export const GridlerGoAPIExampleEventlog = () => {
</Gridler> </Gridler>
<Divider /> <Divider />
<Group> <Group>
<TextInput
leftSection={<>S</>}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search"
value={search}
w="190px"
/>
<TextInput <TextInput
onChange={(e) => setSelectRow(e.target.value)} onChange={(e) => setSelectRow(e.target.value)}
placeholder="row" placeholder="row"