1

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
    }
  });
});
3
  • 1
    Assuming you want to change the data in the outer scope, remove the var from within the #seade click handler, although note that this won't affect the data source you gave to igCombo. Presumably you need to destroy/reinitialise that library, or use a 'refresh' method - assuming it provides one Commented Mar 20, 2017 at 11:14
  • How can I use 'refresh' method? Commented Mar 20, 2017 at 11:21
  • It all depends on if the library you're using has one. Read their documentation Commented Mar 20, 2017 at 11:21

3 Answers 3

2

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" }
        ];
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.