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

Adding and then removing a row does not trigger a save to server

7 Answers 610 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Magnus
Top achievements
Rank 1
Magnus asked on 29 Oct 2013, 01:08 AM
I have a plain ASP.NET/HTML solution (no MVC or wrappers), and I use PageMethods that are called by the read, create, update, destroy (from dataSource).
Like this (only create shown, the others are same except the webmethod):
                var dataSource = new kendo.data.DataSource({
                    batch: true,
                    transport: {
                        read: {
                            type: "POST",
                            url: "default.aspx/GetUserInfos",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                      .... .... ....

And it seem to work most of the time, but if I open the grid (which gets values from server), add a row, save changes (causes update on server), delete the new row and saves changes again, no server call is made. Its like I need to tell the grid that now the new row is permanent.

I also get a crach in some dynamic javascript method if I add a row, save change and then press Cancel toolbar button (at this stage cancel should not do anything, since everything is recently saved to server).

By the way, I had to modify parameterMap like this to get the arguments to be unpacked correctly by ASP.NET
 
parameterMap: function (data, type) {
     if (type == "read")
         return { users: kendo.stringify(data.models) };
     else
         return "{ users:" + kendo.stringify(data.models) + "}"; // sent as argument to ASP.NET, needs to be a string of JSON
 }

7 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 30 Oct 2013, 12:06 PM
Hi Magnus,

 
It seems that currently the grid is not correctly configured as after creating new record it should be send through the "create" transport option. From the provided information however it's not clear what is the exact reason for current behavior - could you please provide runable example where the issue is reproduced to be able to investigate further? 

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Magnus
Top achievements
Rank 1
answered on 30 Oct 2013, 02:23 PM
Note that the grid is in batch mode, and if I just remove or add a row and then press "update" everything works as it should. But if I add a row, update the changes, delete a row and update again, the last update is not happening. Note that at this point, the grid is back to its original data, but since we saved after adding a row it should do an update.
0
Magnus
Top achievements
Rank 1
answered on 30 Oct 2013, 03:48 PM
Attached a test project, when running simply add a row, save and press undo and the saved row will be removed (and Null sent on next Create). Many other ways to get error, wrong called update, etc (and easy to get javascript errors in json). I assume I need to do something different :-)
0
Vladimir Iliev
Telerik team
answered on 01 Nov 2013, 11:56 AM
Hi Magnus,

 
After reviewing the provided project it seems that the server doesn't return any response on creating new record which is invalid configuration. The grid expects the newly created records to be returned with their correct IDs set on the server side. Please check the example below:

[WebMethod]
public static SomeData[] Create(SomeData[] data)
{
    for (int i = 0; i < data.Count(); i++)
    {
        Random ran = new Random();
        //generate unique ID - should come from dataBase
        data[i].Name = "Name " + (100 + data.Count() + ran.Next(100,1000).ToString();
    }
    //return the created records to the client side
    return data;
}
Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Magnus
Top achievements
Rank 1
answered on 01 Nov 2013, 02:22 PM
Thanks for the investigation, it does improve the situation. Is there any documentation about how/what the server should return, because I can't find any? Should Update and Destroy also return something?

Also, testing on sample http://demos.kendoui.com/web/grid/editing.html has the same problem: adding a row, saving it and cancel removes the row. This seems like a bug to me.
0
Accepted
Vladimir Iliev
Telerik team
answered on 05 Nov 2013, 02:10 PM
Hi Magnus,


You can find the documentation about the transport read / create / update and destroy actions in the dataSource API:
Also about the demo that you mention - actually the data is not removed - it just rendered at the last page after the "cancel changes" because new records are inserted at the end of the data.

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Magnus
Top achievements
Rank 1
answered on 05 Nov 2013, 08:45 PM
Thanks for the help, I got it working now.
Tags
Grid
Asked by
Magnus
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Magnus
Top achievements
Rank 1
Share this question
or