How to add a row (which is fetched from DB) to an existing Kendo Grid

4 posts, 0 answers
  1. Naga
    Naga avatar
    21 posts
    Member since:
    Jul 2015

    Posted 15 Sep 2015 Link to this post

    Hi 

    I have textbox, a button and a Grid in my screen, i am binding data to it on a button click with the textbox input.

    If the user clicks the button again with different inputs, i have to go to DB, get data  and append the new data to the existing Grid data.

    I should not lose the existing data and i need to append new data to the same grid I should be able to call the same URL to get data.

    Please let me know how I can achieve this.

     

    Sample Code: 

    <input type="text" class="k-textbox"/>

    <button id="btnAdd">Add</button></td>

    <div id="grid"></div>
    <script>

     $("#btnAdd").on('click', function () {

    $("#grid").kendoGrid({
                    dataSource: {
                        type: "json",
                        transport: {
                            read:
                                {
                                    url: // my url with textbox inputs,
                                    cache: false
                                }
                        },
    schema: {
                            model: {
                                fields: {
    ID: {type: "string"},
    Name: {type: "String"}
       }
                            }
                        },

     columns: [
                    //{ hidden: true, field: "AssetID", editable: false },
                    { template: "<input type='checkbox' class='checkbox' />" },
                    { field: "ID"},
                    { field: "Name"}]
     }).data("kendoGrid");
    });
    });

    </script>

     

     

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Sep 2015 Link to this post

    Hello Naga,

     

    I believe in this case using the add method of the DataSource will work for your case. This allows you to add new row with predefined data. Please refer to the http://dojo.telerik.com/oDELA example. 

     

    In your scenario you can get the value of the input and add a new model with the input's value as shown in the example. 

     

    Regards,
    Boyan Dimitrov
    Telerik
    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. UI for ASP.NET MVC is VS 2017 Ready
  4. Naga
    Naga avatar
    21 posts
    Member since:
    Jul 2015

    Posted 17 Sep 2015 in reply to Boyan Dimitrov Link to this post

    Thanks Boyan Dimitrov 

    It worked great.

    After some googling , i found Insert Method too, 

    which is better to use ? Insert or Add 

  5. Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 21 Sep 2015 Link to this post

    Hello Naga,

     

    both do the same - the insert accepts an index, too.

     

    Regards,
    Petyo
    Telerik
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready