Hi,
The Telerik example for Inline Editing with Custom Editors uses a dropdown list with reference data hardcoded into the custom dropdown cell. This isn't a realistic scenario for for production code with dynamic reference data. If you pass the reference data for the dropdown to the custom cell then the dropdown loses focus every time you change the selected value. This can be seen by shifting the localizedData in the Telerik example referenced earlier from myDropDownCell.tsx to main and passing it as a parameter: https://stackblitz.com/edit/react-9ycz1i?file=app/main.tsx
Is there a workaround for this issue?
Kind regards,
David
Hello David,
You will have to use the Context for passing any additional data/functions/etc. to the custom editor, but it is not necessary to use multiple Contexts. Instead, you can pass all of the additional data with one Context:
Another syntax that might be more flexible in some cases would be the following:
return (
<EditContext.Provider
value={{
gridContext: { localizedData, validator: validation, handleBlur },
}}
>
const DropDownCellProvider = (props: GridCellProps) => { const { gridContext } = React.useContext(EditContext); debugger; return DropDownCell(props, gridContext); };
Then in the custom cell you can use:
export const DropDownCell = (props: GridCellProps, gridContext: any) => { const v = gridContext.validator;
Hope this helps.
Regards,
Konstantin Dikov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Konstantin,
Does that mean that if I want to do custom validation and also handle onBlur for one of the editors for example, then the necessary validation models and onBlur handlers should also be passed using Context? I have updated the example to demonstrate what I mean:
https://stackblitz.com/edit/react-9ycz1i-iwak9v?file=app/main.tsx
Kind regards,
David
Hello David,
The example demonstrates how to pass additional data to the custom editor from the main component through the Context Provider:
<EditContext.Provider value={{ additional data }}>
For your convenience, I have modified the example that you have provided to use context for passing the localizedData to the editor:
As you will notice, the inline definition in the cell is replaced and a provider is used for passing the additional data through the context.
Please let us know if any further assistance is needed.
Regards,
Konstantin Dikov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Konstantin,
That doesn't really help as the reference data is loaded by the main component. The example also has nothing to do with dropdowns and dynamically loaded reference data.
Are you saying it's impossible to have dynamic reference data for a dropdown in a Grid unless the reference data is loaded separately and passed using Context? If that is the case then we won't use the Grid for editing.
Kind regards,
David
Hello David,
The issue that you are facing is due to the inline function within the render, which forces React to re-mount the main component, thus causing the focus to be lost. For avoiding this, you should use React Context for passing additional data to the custom cell and declare it outside of the main component.
Here is an example for passing additional data through Raect.Context to a custom cell:
Hope this helps.
Regards,
Konstantin Dikov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.