jQWidgets Forums

jQuery UI Widgets Forums Lists ComboBox Can't set preselected values

This topic contains 5 replies, has 2 voices, and was last updated by  Peter Stoev 11 years, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • Can't set preselected values #48298

    Maksv
    Participant

    Hello!
    I can’t preselect values from database to dynamicaly created comboboxes.
    Here is my code:

    $("#editBtn").on('click', function() {
    
    						var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');
    						var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',selectedrowindex);
    
    						/*Get preselected values from database */
    						var source = {
    							datatype : "json",
    							datafields : [ {
    								name : 'id',
    								type : 'float'
    							}, {
    								name : 'name',
    								type : 'string'
    							} ],
    			url : '<s:url namespace ="/doctor" action="getDoctorSpeciality?id='+ dataRecord.id+ '"/>'
    									};	
    						
    					
    						var dataAdapter = new $.jqx.dataAdapter(source,
    								{autoBind:true,
    								loadComplete : function(records) {
    								// get data records.
    								var length = records.length;
    								// loop through the records and display them in a table.													
    									for (var i = 0; i < length; i++) {																
    											var record = records[i];
    											_addComboBox(record.name);
    								};
    						},
    						loadError : function(jqXHR,status,error) {},
    						beforeLoadComplete : function(records) {}
    						});
    
    						
                                                 /*Create new combobox*/						
    						function _addComboBox (value) {
    							
    							/*Get all values from database */
    							var source = {
    								datatype : "json",
    								datafields : [ {
    									name : 'id',
    									type : 'float'
    								}, {
    									name : 'name',
    									type : 'string'
    								} ],
    								url : '<s:url namespace ="/doctor" action="jsonSpeciality"/>'
    										};	
    							
    						
    							var dataAdapter = new $.jqx.dataAdapter(source);
    									
    						
    							
    							var comboBoxTag=$('<p id="doctorSpeciality[]"></p>');
    			
    							$(comboBoxTag).jqxComboBox({source : dataAdapter,
    				 	   					displayMember : "name",
    										valueMember : "id",
    										width : 200,
    										height : 20,
    										autoDropDownHeight : true
    									});
    						/*tying to set value */		
    						<strong>$(comboBoxTag).jqxComboBox('val',value);</strong>
    						$("#addRow").before(comboBoxTag);
    									
    							};
    					}
    					)
    Can't set preselected values #48310

    Peter Stoev
    Keymaster

    Hi Maksv,

    In order to select an item, the ComboBox should have items. In the provided code, you bind the ComboBox through Ajax which means that your code for selection should go into a “bindingComplete” event handler or in the dataAdapter’s loadComplete callback function.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Can't set preselected values #48323

    Maksv
    Participant

    Hi Peter,
    actually I have tried to set the value in loadComplete callback function and it works right if I have only one combobox.
    If I have two or more comboboxes than loadComplete function fires only after the last created combobox.
    The same situation with “bindingComplete” event handler.
    May be I should have different dataAdapters for each combobox?

    ....
    $(comboBoxTag).jqxComboBox({source : dataAdapter,
    	displayMember : "name",
    	valueMember : "id",
    	width : 200,
    	height : 20,
    	autoDropDownHeight : true
    	});
    $(comboBoxTag).on("bindingComplete", function (event) {
    $(comboBoxTag).jqxComboBox('val',value);	}); 
    ...
    Can't set preselected values #48325

    Peter Stoev
    Keymaster

    Hi Maksv,

    Each ComboBox should have its own dataAdapter.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Can't set preselected values #48329

    Maksv
    Participant

    Hi Peter,
    thank you for replies.
    Yeahp, it works fine.

    Can't set preselected values #48330

    Peter Stoev
    Keymaster

    Thank you for using jQWidgets!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.