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

Issues adding a row using the API

5 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frik
Top achievements
Rank 1
Frik asked on 09 Feb 2012, 02:52 PM

$("#shortList").kendoGrid({

            height: 400,

            columns: [{

                field: "name",

                title: "Name"

            }],

            dataSource: {

                data: [

                    {

                        name: "Test"

                    }]

            }

        });


then I get this exception when trying to add a row using API later:
TypeError: 'undefined' is not an object (evaluating 'this._set.indexOf')


$("#shortList").data("kendoGrid").addRow();

Using the latest commercial version of your software.  How do I add a row using API?

5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 10 Feb 2012, 07:10 AM
Hello Frik,

In order to use the addRow method you have to make your grid editable and to define a model in your dataSource's schema.
Please check the following example:

$("#shortList").kendoGrid({
    height: 400,
    columns: [{
        field: "name",
        title: "Name"
    }],
    dataSource: {
        data: [
            {
                name: "Test1"
            }
        ],
        schema: {
            model: {
                id: "name",
                fields: {
                    name: { editable: true, nullable: true }
                }
            }
        }
    },
    editable: true
});

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
Edwin
Top achievements
Rank 1
answered on 14 Mar 2012, 10:16 PM
It seems like a horrible limitation to the API to require a grid to be editable in order to use addRow(). Why give the programmer the ability to add a row programatically without allowing the rest of the values to be added via the API? I have been using version 2011.3.1129 just fine to add a row, and then in the detailTemplate, I display a form which does the actual editing. This allows the form for editing a row and creating a new row to appear the same.

I'm doing the same thing with the 2012.1.229 beta, but now every time I call addRow(), it adds a cell editor to the first cell of the new row, even though the grid is not marked editable. This only occurs when using a remote data source. When using a local data source, it behaves as expected by adding a row, but not creating a cell editor.

Here is a demo of the issue with the beta version of kendo.
http://jsfiddle.net/egrubbs/H6dAW/1/
0
John
Top achievements
Rank 1
answered on 15 Mar 2012, 12:03 AM
While I understand your point one of the holes in development platforms has been both the segmenting of technology and the reconnecting of those segments. Many developers tend to think about adding to the HTML rather than adding to a dataset based on the model. The logistics of getting this done can be managing through the table or an external record editor. My thought is either way we are creating a new record in the dataset and the functionality of how the grid works should be servant to that think.
0
Alexander Valchev
Telerik team
answered on 16 Mar 2012, 02:23 PM
Hello guys,

Edwin, I believe that you are looking for the add method of the dataSource - it adds a new model instance to the grid's data no matter if the grid is editable or not. The addRow method of the grid is supported only in editable mode.

Greetings,
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
Joshua
Top achievements
Rank 1
answered on 26 Apr 2012, 05:36 PM
So are we saying that the datasource add will automatically make the grid update with the new row? Also do we then have to call editRow from the grid to put this new item in edit? I think most people are just going to have to rewrite the functionality that edward is trying to accomplish with grid.addRow . I am also in agreement that we should be able to add a new row without making the grid editable.
Tags
Grid
Asked by
Frik
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Edwin
Top achievements
Rank 1
John
Top achievements
Rank 1
Joshua
Top achievements
Rank 1
Share this question
or