Null reference when adding a new row to a grid.

3 posts, 0 answers
  1. Jim
    Jim avatar
    26 posts
    Member since:
    Mar 2016

    Posted 15 Apr 2016 Link to this post

    I am getting the error:  JavaScript runtime error: Unable to get property 'xxx' of undefined or null reference.

    This occurs when I click the "Add New Record" in my Kendo grid.

    Does this have something to do with the way the model in setup?

    I was able to add a record previously when my data record was more flattened out.

    Please advise.


    My grid is setup as:

        .Columns(col =>
            col.Bound(x => x.Person.ID);
            col.Bound(x => x.Person.Field1);
            col.Bound(x => x.Person.Field2);
            col.Bound(x => x.Person.Field3);
            col.Command(x => {
                x.Custom("Extra Options").Click("showExtraOptions");
        .ToolBar(x =>
        .Editable(x => x.Mode(GridEditMode.InCell))
        .Scrollable(x => x.Height("auto"))
        .Filterable(x => x
            .Operators(op => op
                .ForString(str => str.Clear()
                    .StartsWith("Starts with")
                    .IsEqualTo("Is equal to")
        .Pageable(p => p
        .DataSource(ds => ds
            .ServerOperation(false) // Paging, sorting, filtering and grouping will be done client-side
            .Model(m =>
                    m.Id(x => x.Person.ID);
            .Read(r => r.Action("GetPerson", "Home"))
            .Create(x => x.Action("CreatePerson", "Home"))
            .Destroy(x => x.Action("DeletePerson", "Home"))
            .Update(x => x.Action("UpdatePerson", "Home"))


    My model is:

    public class PersonModel
        public My_Person Person{ get; set; }
        public List<Person_Options> PersonOptions { get; set; }
    public class My_Person
        public string ID{ get; set; }
        public string Field1 { get; set; }
        public string Field2 { get; set; }
        public string Field3 { get; set; }


  2. Alexander Popov
    Alexander Popov avatar
    1436 posts

    Posted 19 Apr 2016 Link to this post

    Hello Jim,

    This happens because there are columns bound to complex object nested fields. Since there is no default value for those the Person field, it is initially undefined and trying to get the Field1 property of undefined throws an error. My advice is to specify a default value inside the DataSource's Model option.

    Alexander Popov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Jim
    Jim avatar
    26 posts
    Member since:
    Mar 2016

    Posted 19 Apr 2016 in reply to Alexander Popov Link to this post

    Thank you Alexander.  Setting the default resolved my issue.
Back to Top