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

DataSource.sync() doesn't call create.

1 Answer 449 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 08 Mar 2012, 10:59 AM
I would like to add data to a kendoGrid from a form, not a grid toolbar.
I'm able to add data to the grid with the add() method but when I call sync() on dataSource, create: it never gets called.

This example code it's close to my original code statement even if - in fact - I'm using remote data binding. Anyway, it gives me the same results

HTML:
<div class="k-toolbar">
<input type="text" id="inputColor"></input>
<button id="addColorButton">Add Color</button>
</div>
<div id="grid"></div>

JS:
var colors = [{
        "ID": 1,
        "Name": "Blue"},
        {
        "ID": 2,
        "Name": "Red"
        }];
  
    var dataModel = new kendo.data.Model.define({id: "ID"});
    var localDataSource = new kendo.data.DataSource({
            transport:{
                read: function(options){
                    options.success(colors);
                },
                create: function(){
                    alert('Creating...');
                }
            },
            schema: {
                model: dataModel
            }
        });
  
    $('#grid').kendoGrid({
        dataSource: localDataSource,
        columns: [{title:"Color", field:"Name"}]
        });
  
    $('#addColorButton').bind("click", function(){
        localDataSource.add({
            Name: $('#inputColor').val()
            });
        localDataSource.sync();
        });

I'm doing something wrong? Any ideas?

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 09 Mar 2012, 10:29 AM
Hello Roberto,

Seems to be working with .1407 version. See the following jsFiddle:
http://jsfiddle.net/rusev/E3vYH/

Greetings,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Roberto
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or