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

Need help with dataSource.Read

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 18 Apr 2013, 08:02 PM
Hi, I try to change data from a combobox dynamically.
I got a object containing a javascrip array (Module.Collection)
I create the combobox like:
$("#cboListe").kendoComboBox({
    dataTextField: "Nom",
    dataValueField: "Id",
    dataSource: Module.Collection,
    filter: "contains",
    suggest: true,
    index: 1,
});

Then when the user click on a button, I call this function:
this.AddItemColl = function () {
    Item = new ObjetA();
    Item.Id = this.Collection.length + 1;
    Item.Nom = "Nom" + (this.Collection.length + 1);
    this.Collection.push(Item);
 
    var combobox = $("#cboListe").data("kendoComboBox");
    combobox.dataSource.read();
}

The collection object grow, but the combobox do not reflec change wih the dataSource.Read();
Any idea?
Thanks a lot.

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 19 Apr 2013, 04:13 PM
Hi Pierre,

The ComboBox' DataSource is not connected to the Module.Collection array. When DataSource is initialized it creates its own internal observable array that holds the data. Any changes made to the Module.Collection will not affect onto the ComboBox.

If you want to modify the data, please use the DataSource API methods as I already suggested in the other forum thread which you opened.
this.AddItemColl = function () {
    Item = new ObjetA();
    Item.Id = this.Collection.length + 1;
    Item.Nom = "Nom" + (this.Collection.length + 1);
  
    var combobox = $("#cboListe").data("kendoComboBox");
    combobox.dataSource.add(Item);
}


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Alexander Valchev
Telerik team
Share this question
or