ReactKendo Grid Cell Validation and Display error in same cell.

1 Answer 1312 Views
Grid
Saranya
Top achievements
Rank 1
Iron
Saranya asked on 02 Aug 2021, 08:57 AM

We are Using Kendoreact Editable Grid which have Gridcolumn like Name in grid

<GridColumn
                                    field='Name'
                                    title='Name'
                                    width='150px;'
                                    filter='text'
                                    editor='text'
                                    className='k-grid-textbox'

</GridColumn>

how to validation each cell on entering should not be more than 100 letters and show error in same cell inside grid.

I also tried checking for cell and onblur which is not working and getting error in existing flow. Please help how to validate grid cell when entering and show  error message in same cell.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Aug 2021, 09:22 AM

Hello, Saranya,

The validation in the Grid is done using custom cells for the Grid.

- Render a custom cell where the editor for the cell will have its own validation attributes like required, min, max, etc:

https://stackblitz.com/edit/react-x5wmrp-2fkqz9?file=app/main.jsx

In general, the validation logic has to be added by the developer based on the application business logic. We agree that this may require more work initially, but as React is based on reusable components and logic, once a validation cell is made for one Grid, it can be reused in many others.

Regards,
Stefan
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/.

Saranya
Top achievements
Rank 1
Iron
commented on 02 Aug 2021, 09:59 AM

Thank you for quick reply. one more doubt is that possible to set min and max in this gridcell
Saranya
Top achievements
Rank 1
Iron
commented on 02 Aug 2021, 10:05 AM | edited

I am also facing one more issue. style are getting changed when i use cell event
Stefan
Telerik team
commented on 02 Aug 2021, 10:08 AM

The example uses logic for min and max validation.

Could you please share more details on the type of validation that is needed?
Saranya
Top achievements
Rank 1
Iron
commented on 02 Aug 2021, 10:39 AM

1. I changed above code value <1 || value <30 as value.length <100 as i am checking for letters not to be more than 100

actual validation is min 1 and max 100 letters 

2. I have separate onclick event performs other functionlity like loading child grid etc.

but after adding to cell event for particular column onclick is not triggering and inedit is not working.

Saranya
Top achievements
Rank 1
Iron
commented on 02 Aug 2021, 11:03 AM

Please check this one how styles getting differ which is always edtiable.. only hen user click particular cell onclick wil get triggered and  row will be editable. but now page load itself this one shows as input box.
Stefan
Telerik team
commented on 02 Aug 2021, 12:42 PM

This occurs as when the cell is custom, we are not the ones that render it and have no access to attach the events.

In that case, the developer has to call the same method to enter edit and render two different TD elements based on the edit state.

I updated the example to showcase this:

https://stackblitz.com/edit/react-lwkcwk?file=app/main.jsx
Saranya
Top achievements
Rank 1
Iron
commented on 02 Aug 2021, 03:20 PM

Thanks a lot  and My issue resolved.
Saranya
Top achievements
Rank 1
Iron
commented on 03 Aug 2021, 06:17 AM

I have one more doubt, is that possible to configure min and max for each column and based on it to trigger error 

 currently hardcoded like 1 and 100 in min and max instead to pass as paramter so that can be configurable 

Stefan
Telerik team
commented on 03 Aug 2021, 06:35 AM

As this is a custom function, the developer can dynamically pass extra parameters like min and max:

https://stackblitz.com/edit/react-lwkcwk-zcyyue?file=app/main.jsx

The demo only shows a possible approach, but in the real application the developer can set it up differently.

Saranya
Top achievements
Rank 1
Iron
commented on 03 Aug 2021, 02:45 PM | edited

yes its working for single validation only 

https://stackblitz.com/edit/react-lwkcwk-7ptsg1?file=app/main.jsx 

for ProductName min=0 and max =30

for ProductAlternateName min =0 and max =10

but in this above code link showing same error for both column considering max as 30

also i have one column to validate like only max it can be null too 

Please check this link how to configure different validation based on passing min and max 

 

Stefan
Telerik team
commented on 04 Aug 2021, 10:48 AM

The issue occurs as the logic is checking for the field name where it is not available.

This:

    if (props.dataItem.field = "ProductName") {
        min = 1; max = 30;
    }
    else if (props.dataItem.field = "ProductAlternateName") {
        min = 1; max = 10;
    }
Should be this:

    if (props.field === "ProductName") {
        min = 1;
        max = 30;
    }
    else if (props.field === "ProductAlternateName") {
        min = 1;
        max = 10;
    }
After I updated the example, it was correctly set for the different fields.

Also, please have in mind that the validation logic is on an application level, not inside the Grid. This means that its implementation will vary based on the real application. The demo is to only show a possible approach.
Saranya
Top achievements
Rank 1
Iron
commented on 05 Aug 2021, 06:00 AM | edited

yes i understand , how to manage when there is error not to allow details to save and remain in same page.

Also how to highlight outline column when error 

Stefan
Telerik team
commented on 05 Aug 2021, 11:09 AM

This can be done by keeping the information in the state that field X is not valid. Then when the users want to save it to allow the save only when there are no errors. This is something that has to be done at the application level. The Grid is only showing the data that it receives, it has no control over the validation or submitting the data. In these cases, we recommended the developers choose what is best for their application as our suggestions could not fix every application's requirement.
Saranya
Top achievements
Rank 1
Iron
commented on 05 Aug 2021, 01:06 PM

Is that possible to stop focus moving from one row to another row until error message d isplaying?
Stefan
Telerik team
commented on 05 Aug 2021, 01:18 PM

The developer can use the same information if there is an invalid value and not place another item in edit until there are no invalid values.
Saranya
Top achievements
Rank 1
Iron
commented on 05 Aug 2021, 02:11 PM

Please share any sample code suggestion in same above link , will be useful 
Stefan
Telerik team
commented on 06 Aug 2021, 07:51 AM

I updated the example to show a possible approach: https://stackblitz.com/edit/react-lwkcwk-zcyyue?file=app/main.jsx

Please have in mind that this is custom logic, it is based on the application not on the Grid features.

If you have an additional request for custom functionalities I can recommend our Professional Services team that assist with these requests:

https://www.progress.com/services

Tags
Grid
Asked by
Saranya
Top achievements
Rank 1
Iron
Answers by
Stefan
Telerik team
Share this question
or