Somepub
Somepub

Reputation: 435

How do I change array variable

I have an variable array called data, for IGcombobox datasource, I want to change the array when I click my #select, how can I do that? With this code it doesn't change the variable. Also I could just use php, but I dont want to do that!

<div id="checkboxSelectCombo" name="kanal" style="position:absolute;" ></div>

<select id="seade" name="seade">        
  <?php for($i = 1; $i <= $devi; $i++) {
    echo '<option value="' . $i . '">' .$device_name[$i]. '</option>';
  } ?>
</select> 
$(function () {
  var data = [
    { ID: "1", Name: "Vooluandur 1" },
    { ID: "2", Name: "Meeter 1" }
  ];

  $("#seade").on('click', function(event) {
    console.log($("#seade").val());
    if ($("#seade").val() == 2) {
      var data = [
        { ID: "3", Name: "Vooluandur 2" },
        { ID: "4", Name: "Meeter 2" }
      ];
    }
  });

  $("#checkboxSelectCombo").igCombo({
    width: "100px",
    dataSource: data,
    textKey: "Name",
    valueKey: "ID",
    multiSelection: {
      enabled: true,
      showCheckboxes: true
    }
  });
});

Upvotes: 1

Views: 152

Answers (3)

Somepub
Somepub

Reputation: 435

I found a solution, since changing data variable doesn't affect igCombo datasource, I can just change datasouce variable like this

var data2 = [{
    ID: "3",
    Name: "Vooluandur 2"
    },
    {
    ID: "4",
    Name: "Meeter 2"
    }
];

$("#seade").on('change', function(event) {
    if (this.value == 2) {
        $("#checkboxSelectCombo").igCombo({
            dataSource: data2,
            textKey: "Name",
            valueKey: "ID",
        });
    }
});

Documentation source: http://www.igniteui.com/help/igcombo-data-binding

Upvotes: 0

Rakesh Shukla
Rakesh Shukla

Reputation: 94

Had found something to refresh the datasource hope it will work

where you update your "data" variable below that put this line

$("#checkboxSelectCombo").igCombo("option", "dataSource", data);

This should change the dataSource and rebind the combo.

Upvotes: 0

fabienheureux
fabienheureux

Reputation: 400

You could try this: (didn't run it though)

$("#seade").on('change', function(event) {
    if (this.value == 2) {
        data = [
            { ID: "3", Name: "Vooluandur 2" },
            { ID: "4", Name: "Meeter 2" }
        ];
    }
});

Upvotes: 2

Related Questions