igcombo doesn't work with dynamic DIV element

242 Views Asked by At

igcombo works fine when using a static div element, however if I added the div element dynamically to the page the igcombo box data won't be populated. Is there any thing I can try to make this work?

 $("#combo").igCombo({
            dataSource: data, //JSON Array 
            valueKey: "ID",
            textKey: "Name"
        });



<div id="combo"></div>
1

There are 1 best solutions below

0
On

The igCombo and any other widget needs to be initialized on an element that already exists in the DOM. In order to have it work with a container that you create dynamically, you simply need to call the initialization code after the element is added to the DOM.

$.ajax({
    ...
    success: function (data) {
        var combo = $('<div id="combo"></div>').appendTo(document.body);
        combo.igCombo({
            dataSource: data, //JSON Array 
            valueKey: "ID",
            textKey: "Name"
        });
    }
});