Hi,
When using syncfusion grid with react and typescript, I'm facing the below issue,
Type '(args: IIndexable) => void' is not assignable to type 'EmitType<PageEventArgs | GroupEventArgs | FilterEventArgs | SearchEventArgs | SortEventArgs |
... 4 more ... | ActionEventArgs>'.
I have a grid where I mentioned 'actionBegin' property,
<GridComponent
dataSource={tabledata}
columns={currentColumns}
allowSorting={true}
allowPaging={true}
ref={grid}
actionBegin={onActionBegin}
pageSettings={{ pageCount: 10, pageSizes: [10, 20, 'All'] }}
showColumnChooser={true}
allowResizing={true}
allowTextWrap={true}
min-Width
rowHeight={60}
filterSettings={FilterOptions}
allowFiltering={true}
>
const onActionBegin = (
args: IIndexable
) => {
if (args?.requestType === 'filterbeforeopen' && args.columnName === 'companyNames') {
args.filterModel.options.dataSource = companyNames
}
}
So, the error is thrown only when I specify a particular type for 'args' param, but when I use typeDef of 'args' as 'any' instead of my own reference type, its working fine.
But, I can't use 'any' since I want to specify the expected/actual typedef for 'args' in the onActionBegin function.
I already tried with different types for 'args' param including 'FilterSearchBeginEventArgs'
and all the other types mentioned in the error as expected types (GroupEventArgs | FilterEventArgs | SearchEventArgs | SortEventArgs) but none resolves my issue.
Hence, I created my own type reference interface object, with 'any' reference to its properties. I mentioned my 'IIndexable' interface below for your reference.
interface IIndexable {
[name: string]: any
}
In spite of doing all this, I'm not able to fix the error. Please help me in this regard. Thanks
|
const actionBegin = (args?: GroupEventArgs | PageEventArgs | FilterEventArgs) => { //actionBegin event of Grid
if((args as FilterEventArgs).requestType as string === 'filterbeforeopen') {
((args as FilterSearchBeginEventArgs).filterModel as ExcelFilterBase).options.dataSource = DataUtil.distinct(sdata, 'ShipCountry', true);
}
}
|