Need help with dataSource.Read

2 posts, 0 answers
  1. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 18 Apr 2013 Link to this post

    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.
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 19 Apr 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
Back to Top