This is a migrated thread and some comments may be shown as answers.

batch edit issues multiple grids

3 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 08 May 2017, 08:32 PM

I have a page that has two grids. I need to collect all the data from both grids as well as additional info from various other controls on the page and validate, then save it. If the data doesn't validate against our validation logic, I need to allow the user to make necessary changes then attempt to save again.

This page is solely for new data, so technically there is no datasource to connect to. Here's what I've done. The grids are set up for Ajax and are batch edit. I've got a button on my page that calls JS to save changes to both grids if either of them has changes. Otherwise, it triggers a save changes of the rest of the page data. I've set my grids to bind to public properties on my page that are pulling from a Session Object. This way when I save the rest of the page data in the Page_PreRender event, I can combine it with the rest (the two grids feed child collections off a main object, being populate from the various other controls on the page).

But I've got a snag. How do I reset the grid records, so that if I can't save due to validation, when the user clicks the save button again, the grid is still triggering an Insert instead of an Update?

Reading through other threads made me think it had something to do with ajax, but because I don't have a true datasource, ajax is what is keeping the data in the grid when the user clicks the save button. And I need this to happen in case of a validation failure.

I hope all this makes sense. Can anyone help? Maybe there is a better way to collect all this new data. I'm just not sure.

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 11 May 2017, 12:55 PM

Hello Rayne,

First of all, make sure to provide a data source to the grid in its NeedDataSource event even if there will be no data in it.

Then, if validation fails and you want the grid to be empty, you can:

  • call the Rebind() method of the grid
  • pass an empty data source (you could use a flag or it could be the old empty source, that depends on your page logic)
  • ensure the grid is part of the AJAX response (probably tweak a bit the AJAX setup on the page)

You may also find interesting this thread on putting the data from two batch edit grids in the same request: http://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button

Also, if the grid validations succeed, you can still process the rest of the form in the same request because all inputs are part of the POST query.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Rayne
Top achievements
Rank 1
answered on 11 May 2017, 01:05 PM

Thanks for the reply.

If validation fails, I want the grids to retain the data the user entered so they can correct any errors and try again. But with batch, the grid clears when a postback occurs. At least that is my understanding. That was the reason for doing the submit via ajax. And using a session object tied to a property for the datasource.

0
Marin Bratanov
Telerik team
answered on 11 May 2017, 01:15 PM

Hi Rayne,

Then, you can store the user input in the Session variable regardless of the validation and provide it to the grid DataSource property even if validation fails. Note that there will be no indication on what exactly is the invalid data so you may need to construct appropriate error message section on your page.

I also advise you look into using client-side validation in the grids to reduce the validation problems on the server to a minimum: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/batch-editing/validation.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Rayne
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Rayne
Top achievements
Rank 1
Share this question
or