jQWidgets Forums
jQuery UI Widgets › Forums › Grid › JqxCombobox remote source
Tagged: combobox, grid, initeditor, jqxComboBox, jqxgrid, select, selectedIndex
This topic contains 5 replies, has 3 voices, and was last updated by sainish 10 years, 10 months ago.
-
Author
-
I am using JqxCombobox remote source. The problem i am facing is i want to already select value depending on id in combobox when i open record in editing mode
Hello sainish,
I am not sure I understand your requirement, but if you wish to have a default selected value each time you enter edit mode, you can achieve this in the initeditor column callback function, e.g.:
columns: [ { text: 'Ship Country', datafield: 'ShipCountry', width: 150, columntype: 'combobox', createeditor: function (row, column, editor) { // assign a new data source to the dropdownlist. var list = ['Germany', 'Brazil', 'France']; editor.jqxComboBox({ autoDropDownHeight: true, source: list }); }, initeditor: function (row, cellvalue, editor, celltext, pressedkey) { editor.jqxComboBox({ selectedIndex: 2 }); } },
In the example, “France” will be selected each time but you may set the selectedIndex to a variable that changes dynamically.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/` var source =
{
datatype: “json”,
datafields: [
{ name: ‘prod_id’ },
{ name: ‘prod_name’ }],
url: “<?= base_url();?>helpers/productSearch”,
data: {
featureClass: “P”,
style: “full”,
maxRows: 12,
username: “jqwidgets”
}
};
var dataAdapter = new $.jqx.dataAdapter(source,
{
formatData: function (data) {
if ($(“#jqxcombobox”).jqxComboBox(‘searchString’) != undefined) {
data.name_startsWith = $(“#jqxcombobox”).jqxComboBox(‘searchString’);
return data;
}
}
}
);
$(“#jqxcombobox”).jqxComboBox(
{
width: 250,
height: 25,
source: dataAdapter,
remoteAutoComplete: true,
autoDropDownHeight: true,
selectedIndex: 0,displayMember: “prod_name”,
valueMember: “prod_id”,
selectionMode: “dropDownList”,
// multiSelect: true,
renderer: function (index, label, value) {
var item = dataAdapter.records[index];
if (item != null) {
var label = “(” + item.prod_name + “, ” + item.prod_id + “)”;
return label;
}
return “”;
},
renderSelectedItem: function(index, item)
{
var item = dataAdapter.records[index];
if (item != null) {
var label = item.name;
return label;
}
return “”;
},
search: function (searchString) {
dataAdapter.dataBind();
}
});how could i set default select some value if i have id or value
Hi sainish,
I would like to answer your question instead of my colleague. You cannot select something which is not loaded. THe remote source sample of jqxComboBox demonstrate how to load items in jqxComboBox when you type something. Loading is on demand which means that the data is being loaded as you type. So, you can’t select something which is not loaded. Otherwise, if your data is not loaded on demand, you may use the Dimitar’s solution.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks but i got the solution with this two line
$("#customercombobox").jqxComboBox('insertAt',{alt_name: "<?php echo $alt_name; ?>",cust_id: "<?php echo $cust_id; ?>",name: "full name"},0); $("#customercombobox").jqxComboBox('selectIndex', 0 );
-
AuthorPosts
You must be logged in to reply to this topic.