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

Kendo Grid add row calls submit changes multiple times

5 Answers 1884 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 08 May 2012, 11:14 PM
I have a Kendo grid that allows adding a new record. When the user adds a record it not only submits the current new record, but also resubmits all previously submitted new records. That is:
  • add first new record, submit record 1
  • add second new record, submit record 1,2
  • add third new record, submit record 1,2,3
  • etc.
This quickly creates MANY duplicate records in my DB.

Is this related to "batch"? I have it set "batch: false"

Thanks,
DJo

Edit:
I might have the problem. I'm using parameterMap with a switch on type; case "create" pushes a new object onto a changeSet array then does "return (JSON.stringify({ "changeSet": changeSet }))". I think this might just be building up an array of changes that grows with each create and gets sent each time.
Is it OK to splice the array after the return statement?

5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 09 May 2012, 04:10 PM
Hello David,

The problem is most probably connected with the server response - the service should return the inserted item else it will continue to be interpret as a new one.

For more detailed information on this subject, please check these forum topics:

All the best,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 09 May 2012, 04:21 PM
Thanks, Alexander. I've checked and the server is returning the correct data. The issue is not that the grid is showing multiple rows - add new record actually calls the SubmitChanges method once for every previous insertion. The number of calls increments with each new addition so the database is filling up with duplicate records.My edit to the original post is nonsense - the changeSet

My edit to the original post is nonsense - the changeSet array is local to the parameterMap function so it isn't growing with each call.

I think it actually is related to batch. I've set batch to true and the behavior has gone away (i.e. each addition only adds the latest addition).

Any idea why this would be? I'm watching the code and I can see it going into the parameterMap function over and over again, and Fiddler is showing all these SubmitChanges calls.

EDIT
Actually batch=true does not fix it. The multiple calls go away but it no longer sends data to the database; all the changeSet entities are empty.
0
David
Top achievements
Rank 1
answered on 09 May 2012, 04:33 PM
Here is a fiddler screen shot showing the call/response made on adding a new record. I believe this means the server is returning the created object, no?
  
1
David
Top achievements
Rank 1
answered on 10 May 2012, 08:51 PM
I think I've tracked down the problem...

The data that is returned by a read is different than that returned by a create, update, or delete operation. The schema is set up based on the data returned from a read, therefore the datasource is unable to recognize that returned by a create.

This seems to be inherent in the JSON factory used by .NET to expose CRUD endpoints from a WCF Domain Service. It creates distinct endpoints for "get" and "post" type operations, which return different schemas. Specifically the root element is different for the JSON returned by the two endpoints, so the dataSource:schema:data elements need to be specified separately.

Any idea how to specify different data elements for the various transport methods? There seems to be only one schema with one data element per datasource. Could I write code under parameterMap that sets this element depending on the transport method?

Thanks,
David

P.S. I'm going to duplicate this last question in the datasource forum, where it seems more appropriate. Feel free to abandon this thread.
0
Michel
Top achievements
Rank 1
answered on 23 Feb 2013, 01:29 PM
First of all, thank you for this thread, it fixed a problem for me, which took me aver 16 hours of search and rolling around myself.

Second, As i am trying out Kendo UI, to find out if it can accelerate my development of forms and grids extensive apps, i must say that this piece of information was really overlooked in the documentation [not in tutorials, not in forum threads].

I am recommending that you add the following to the docs:-
1- specify the expected return from the read/create/update/delete urls.
2- make sure that the exact record, with correct id, with same data grid format is returned, to avoid duplicate calls.

i am building an input form for adding/editing new records and reflect them in the grid.
it took me some time to understand how to created shareable datasource, and sync after CRUD with Grid. i would have wished for an easier way to do that, or at least a clear sample.

the Put/Delete are not standard, and i had to exchange them with regular post in php. that could have saved me lots of time if i knew earlier.

Thank you all, and thanks again for this thread.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
David
Top achievements
Rank 1
Michel
Top achievements
Rank 1
Share this question
or