add a new row through javascript in the grid

3 posts, 1 answers
  1. Zora
    Zora avatar
    2 posts
    Member since:
    Jan 2013

    Posted 09 Jan 2013 Link to this post

    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. Answer
    Atanu
    Atanu avatar
    40 posts
    Member since:
    Jan 2012

    Posted 10 Jan 2013 Link to this post

    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.
  3. Zora
    Zora avatar
    2 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    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

Back to Top