jQWidgets Forums
jQuery UI Widgets › Forums › Lists › ComboBox › select item not working in document ready when binding to JSON data
This topic contains 3 replies, has 2 voices, and was last updated by krnacm 11 years, 1 month ago.
-
Author
-
I have created in document ready function an combobox binding to JSON data like this
var source = { datatype: "json", datafields: [ { name: 'Text' }, { name: 'Value' } ], url: "LoadData/_DisabledAjaxLoading", }; var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxWidget").jqxComboBox( { width: 200, height: 25, source: dataAdapter, displayMember: "Text", valueMember: "Value" });
and in the document ready function I want to select an item like this
$("#jqxWidget").ready(function () { $("#jqxWidget").val('disabled); });
I also tried select value (the second in the list) this way with no success
$("#jqxWidget").ready(function () { var item = $("#jqxWidget").jqxComboBox('getItem', 1); $("#jqxWidget").jqxComboBox('selectItem', item); });
but with no sucess, it does’t select the item. Do I something wrong or am I missing something? Any help will be much appreciated.
Thanks
MatejHi Matej,
There is no function called “ready” related to a widget. “selectItem” is expected to be called after your Data is Loaded, not before that i.e with Ajax calls, you should invoke “selectItem” within the dataAdapter’s loadComplete callback function, otherwise you will try to select non existing item.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
please, how do I define the call back function loadComplete within the dataAdapter. I can not find it in the documentation.
Thanks
MatejPeter,
I have found it.
var dataAdapter = new $.jqx.dataAdapter(source, { contentType: 'application/json; charset=utf-8', loadComplete: function () { $("#jqxWidget").val('disabled only'); }, error: function (xhr, status, error) { alert(JSON.stringify(xhr)); } });
Thanks a lot for your help.
Kind regards
Matej -
AuthorPosts
You must be logged in to reply to this topic.