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

add a new row through javascript in the grid

2 Answers 2028 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zora
Top achievements
Rank 1
Zora asked on 09 Jan 2013, 01:53 PM
Hi,

I would like to add a new row to the grid programatically (with certain values, let's say "111", "Mike") everytime a button is clicked(or another event happens, the button clicked is just an example). Can I do that in javascript (hooking the update event on button.click)?

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanu
Top achievements
Rank 1
answered on 10 Jan 2013, 08:59 AM
For adding a new row you can use in your javascript code
var grid = $("#YourGridName").data("kendoGrid");
grid.addRow();
Make sure you have an editable grid.

Hope that helps.
1
Zora
Top achievements
Rank 1
answered on 10 Jan 2013, 01:01 PM
Thank you Atanu! Starting from there, I found the solution to add values as well:

var grid = $("#myGridID").data("kendoGrid");
        var datasource = grid.dataSource;
        datasource.insert({ ColumnName1: 'mydata', ColumnName2: '4445' }); //here mention all the column names, otherwise will get an error

Tags
Grid
Asked by
Zora
Top achievements
Rank 1
Answers by
Atanu
Top achievements
Rank 1
Zora
Top achievements
Rank 1
Share this question
or