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

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

3 Answers 470 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 15 Sep 2015, 08:15 PM

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>

 

 

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 17 Sep 2015, 01:56 PM

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
0
Naga
Top achievements
Rank 1
answered on 17 Sep 2015, 05:03 PM

Thanks Boyan Dimitrov 

It worked great.

After some googling , i found Insert Method too, 

which is better to use ? Insert or Add 

0
Petyo
Telerik team
answered on 21 Sep 2015, 01:29 PM

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
Tags
Grid
Asked by
Naga
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Naga
Top achievements
Rank 1
Petyo
Telerik team
Share this question
or