回调函数未获取更新状态

时间:2020-09-29 14:09:18

标签: reactjs kendo-ui kendo-grid kendo-react-ui kendo-treelist

我正在尝试在自定义过滤器回调函数中获取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>
);

0 个答案:

没有答案