我正在尝试在自定义过滤器回调函数中获取gridDataState
值。每当调用此回调时,gridDataState始终等于defaultSDataState。我试着做一个吸气功能,但仍然有这个问题。当kendo
通过TreeListTextFilter
调用回调时,它将从gridDataState
获取正确的值。我在做什么错,该如何解决?
const [gridDataState, setGridDataState] = useState(defaultSDataState);
const customRangeFilterCell = (field) => (
<RangeFilterCell
onChange={(newVal) => {
console.log(gridDataState) // prints defaultSDataState
handleFilterChange({ field, filter: [{ operator: newVal.operator, value: newVal.value, field }] }, true);
}}
/>
);
function getState() {
return gridDataState;
}
const handleFilterChange = (event, shouldAddState = false) => {
console.log(getState().filter, event); // prints defaultSDataState
if (!shouldAddState) setGridDataState({ filter: event.filter, sort: [] });
return;
}
const allColumns = [
{ field: 'title', title: 'Some title', filter: TreeListTextFilter},
{
field: 'customFilter',
title: 'custom filter',
filter: () => customRangeFilterCell('customFilter')
}
];
return (
<div>
<TreeList
data={processData()}
columns={processColumns(columns)}
{...gridDataState}
onFilterChange={handleFilterChange}
skip={skip}
take={take}
/>
</div>
);