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

TypeError: d is undefined after adding new data

9 Answers 764 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 15 Jan 2013, 09:57 AM
Hello,

I'm using Kendo grid with CRUD functionality. The problem is, the first create functionality works fine but when I want to add another data then i get:
TypeError: d is undefined
in Firebug and I cannot even close the create dialog.
This is the response from server that is a Json file:
{"Data":[{"Id":364,"UserName":"a","Path":"a","PathEscaped":"a\\%"},{"Id":365,"UserName":"b","Path":"b","PathEscaped":"b\\%"}],"Total":2,"AggregateResults":null,"Errors":null}

This is the code in the view:

$("#rulesTable").kendoGrid({
            columns: [
            { field: "UserName", title: "UserName", width: "300px" },
            { field: "Path", title: "Path" },
            { command: ["destroy"], title: " ", width: "200px" }
            ],
            editable: "popup",
            pageable: true,
            toolbar: ["create"],
            dataSource: {
                serverPaging: true,
                pageSize: 10,
                schema: {
                    data: "Data",
                    total: "Total",
                    model: {
                        id: "Id",
                        fields: {
                            UserName: { type: "string", editable: true, nullable: false, validation: { required: true } },
                            Path: { type: "string", editable: true, nullable: false, validation: { required: true } }
                        },
                    }
                },
                batch: true,
                transport: {
                    create: {
                        url: "Rules/AddRule1",
                        type: "POST",
                    },
                    read: {
                        url: "Rules/GetRules",
                        contentType: "application/json; charset=utf-8",
                        type: "POST",
                        dataType: "json",
                    },
                    destroy: {
                        url: "Rules/DeleteRule1",
                        type: "POST",
                        data: {
                            Id: $("#input").val()
                        },
                    },
                    errors: function (response) {
                        var errorData = $.parseJSON(e.responseText);
                        alert(errorData.errorMessage);
                        $("#loading").innerHtml = "error";
                    },
                    parameterMap: function (data, operation) {
                        if (operation === "read") {
                            return kendo.stringify(data);
                        }
                        else {
                            var result = {};
                            for (var member in data) {
                                result["" + member] = data[member];
                            }
                            return result;
                        }
                    }
                },
                sort:
                {
                    field: "UserName",
                    dir: "asc"
                },
                },
            });
Could you please help me why i get this error?

9 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 17 Jan 2013, 08:20 AM
Hi Sam,

I tried to reproduce the problem locally but to no avail – everything is working as expected on our side (please check this screencast). Please provide run-able example where the issue is reproduced – hopefully this will help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sam
Top achievements
Rank 1
answered on 17 Jan 2013, 10:38 AM
Hi Vladimir,

First of all, thank you so much for your answer. I've checked all the details that you show in the screencast (inspect elements) with mine and those are the same.
As I mentioned in the previous post, "Create" function works fine for the first time but it won't when I want to add a new record without refreshing the page. In the screencast, first you add a record in Chrome and then add another record in Firefox. Could you please use just one browser (preferably chrome) to test my code and try to add at least three records in a real DB and check if it works without needs to refresh the page and without get any error?
I'm now creating a new project from my code and I'll send it here soon.

Thanks in advanced,
Best Regards,
Sam
0
Sam
Top achievements
Rank 1
answered on 18 Jan 2013, 04:48 PM
Hi Vladimir,

Here comes my actual working code. Please download the attached file.

Thanks in advanced,
Best Regards,
Sam
0
Vladimir Iliev
Telerik team
answered on 21 Jan 2013, 07:14 AM
Hi Sam,

From the provided information it's not clear for us what causes the issue because of too many missing dependencies - could you please provide run-able project where the issue is reproduced? Also I notice that the project uses unsupported version of jQuery - v.1.9.0 - please note that KendoUI v2012.3.1114 supports jQuery 1.8.2 and you should downgrade to that version. For more information about JavaScript dependencies you can check this article

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sam
Top achievements
Rank 1
answered on 21 Jan 2013, 09:45 AM
Hi Vladimir,

Unfortunately I cannot attach the actual working project to this post since the project is more than 2MB, instead I have uploaded it to Dropbox so you can download it from https://www.dropbox.com/s/l1mtkx94bqjhy0u/BugReport.zip.
I have downgraded jQuery from 1.9.0 to 1.8.2.

IMPORTANT: Before you run the application please open Web.config file in BugReport folder, edit "Data Source" according to your MS SQL server address. Finally rebuild it run it.

Thanks in advanced,
Best Regards,
Sam
0
Accepted
Vladimir Iliev
Telerik team
answered on 21 Jan 2013, 12:51 PM
Hi Sam,

 
After reviewing the provided project it seems that the issue comes from invalid data returned by the "AddRule1" action - currently the action returns all records from the first page to the grid. Please note that the Grid expects only the newly created record to be returned (containing the generated model ID) using JSON data. Please check the example below:

AddRule1 Action:

[HttpPost]
public ActionResult AddRule1()
{
    RulesService rc = new RulesService();
    NameValueCollection nvc = Request.Form;
    Object id = nvc["models[0][Id]"];
    var userName = nvc["models[0][UserName]"];
    var path = nvc["models[0][Path]"];
    Rule newestRecord = rc.AddRule(userName, path);
    return Json(new { Data = newestRecord });
}

AddRule method:
public Rule AddRule(string userName, string path)
{
    Rule newRole = new Rule { UserName = userName, Path = path };
    RuleDepository rd = new RuleDepository();
    rd.AddRule(newRole);
    return newRole;
}

Kind regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sam
Top achievements
Rank 1
answered on 21 Jan 2013, 02:08 PM
Hi Vladimir,

Thank you so much for your answer. I have changed my code according to your comments and now it works fine.

Best Regards,
Sam
0
KHALID
Top achievements
Rank 1
answered on 08 Jul 2015, 12:57 AM

I am facing same issue

 

Can You explain where to put this Code ?

 

0
Vladimir Iliev
Telerik team
answered on 09 Jul 2015, 06:15 AM
Hi Khalid,

The code is specific for the Sam code - that why I would suggest to open a new support ticket / forum post and provide the current Grid and Controller code that you have. This way we will be able to advice you better how to proceed. 

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Sam
Top achievements
Rank 1
KHALID
Top achievements
Rank 1
Share this question
or