jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Problem loading Combobox in Grid in server environment
Tagged: combobox
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 12 years, 4 months ago.
-
Author
-
Hi,
I’m facing problem with loading of combobox in Grid. In the Grid I’ve 4 comboboxes where I’m getting each dropdown data from different entities. It is working fine in Local system while debugging. But when deployed in the server, all the dropdowns were not getting loaded with the data. I spent alot time on it but couldn’t find the solution.Below is the design code I’m using
var accountNameSource =
{
datatype: “json”,
datafields: [
{ name: ‘Name’ },
{ name: ‘Id’ }
],
id: ‘Id’,
root: ‘Rows’,
url: ‘@Url.Action(“GetAccountsData“, “Controller”)’
};//INITIALIZE THE DATA ADAPTER FOR THE ACCOUNT SOURCE
var accDataAdapter = new $.jqx.dataAdapter(accountNameSource, { autoBind: true, async: false });//CODE USED IN COLUMN OF THE GRID
initeditor: function (row, cellvalue, editor) {
var accountId = $(‘#jqxgrid’).jqxGrid(‘getcellvalue’, row, “AccountNameId”);
editor.jqxComboBox({ displayMember: ‘Name’, source: accNameDataAdapter, selectedIndex: Id, checkboxes: false, theme: theme });
editor.bind(‘select’, function (event) {
//GET THE SELECTED INDEX.
selAccountIndex = editor.jqxComboBox(‘getSelectedIndex’);
//GET THE GUID OF THE SELECTED ACCOUNT
if (editor.jqxComboBox(‘getSelectedItem’) != null && selAccountIndex != -1) {
selAccountId = editor.jqxComboBox(‘getSelectedItem’).value;
}
});
}Same code is used for other dropdowns but the source is changed accordingly. Can anyone help me on this.
Regards,
Syai
Hi Syai,
1. accDataAdapter has “autoBind” set to true. That is wrong, because that will result in 2 server calls. 1 automatic after the adapter initialization and another from the ComboBox when you set the source property to point to the dataAdapter.
2. To initialize a combobox, you should use the “createeditor”, not “initeditor”. “initeditor” is called every time when the editor is opened so your code will make server calls on each cell edit which I suppose it not a desired behavior. You should use “initeditor” for selecting the default index of the editor.
3. You bind to “select” event, but you never unbind from it. When you open the editor 3 times, you will have 3 subscriptions to that event.
4. You set unnecessary properties of jqxComboBox like theme and checkboxes. These are already set automatically by the Grid.
5. selectedIndex: Id is incorrect unless the Id is a Number.Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
I’ve modified the code accordingly. Still didn’t get it to work in the server environment. Does the same name for root in source causes conflict to bind data to combobox?root: ‘Rows’,
Regards,
SyaiHi Syai,
It depends on your data source whether you should specify the “root” field or not. If your JSON data is returned in the format: “Rows: […”, then you should the “root” field. Here is a sample which demonstrates how to use jqxGrid with MVC: asp.net-bind-jquery-grid-to-sql-database.htm. The following sample includes editing, too: asp.net-grid-server-side-editing.htm.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.