Hi,
I have another question on having igCombo as editor inside an igGrid. I set up my editor something like this:
features.Updating() .EnableAddRow(true) .EnableDeleteRow(true) .EditMode(GridEditMode.Row)
.ColumnSettings(s =>
{
s.ColumnSetting().ColumnKey("Product").EditorType(ColumnEditorType.Combo) .ComboEditorOptions(options => { options.DataSource(Model.Products).TextKey("ProductName").ValueKey("ProductID"); });
}
When I select a product from the combo, the ProductName is displayed, but when I clicked the 'Done' button, the ProductID is displayed instead of the ProductName.
Is this the intended behavior ? if so, is there any way around it ? I want to display the text value after the edit mode ended.
Also, why is the combo data source not getting the whole object that I passed in from the MVC controller ? let's say my Product entity has ID, Name, Price, and Description. Only the Name and ID are available inside the data source since it's set as Text and Key value.
Thanks,
Jeffrey
Hi Jeffrey,
The behavior is correct, because at the end the igCombo.options.valueKey is what it gets to the underlying data source and that value is displayed in the cell. You can workaround it as I described in this forum thread:
http://ko.infragistics.com/community/forums/p/72892/370474.aspx#370474
jAndika said: Also, why is the combo data source not getting the whole object that I passed in from the MVC controller ? let's say my Product entity has ID, Name, Price, and Description. Only the Name and ID are available inside the data source since it's set as Text and Key value.
I don't know the exact reason, but I guess this is done to save network traffic. textKey and valueKey properties are all that igCombo is needing to do its job and thus the data source is stripped to these two properties.
Best regards,
Martin Pavlov
Infragistics, Inc.
Martin & Viktor,
Thanks for the reply. I run into another problem trying to implement that mapping solution. I'm using MVC helper to build the grid, and below is how I set it:
.Columns(column =>{ column.For(c => c.ProductName).DataType("string").HeaderText("Product").FormatterFunction("lookupProductName");}).Features(features =>{ features.Updating() .EnableAddRow(true) .EnableDeleteRow(true) .EditMode(GridEditMode.Row) .ColumnSettings(s => { s.ColumnSetting().ColumnKey("Product").EditorType(ColumnEditorType.Combo) .ComboEditorOptions(options => { options.DataSource(Model.Products).TextKey("ProductName").ValueKey("ProductID"); }); });})
Here's my lookupProductName function:
function lookupMfrCode(productID) { if(productID) return comboMapProduct[productID];}
The problem is when rendering the grid first time or any regular grid row, the value that gets passed into lookupMfrCode is ProductName instead of ID, and since the mapping key is based on ProductID, the function does not return anything and throws an error.
Am I missing something here ? Is there another property I need to set inside the column or columnSetting ?
There is a typo, the function name should be lookupProductName:
function lookupProductName(productID) { if(productID) return comboMapProduct[productID];}
Ok I'll definitely keep that in mind.
The thing is setting AllowCustomValue to true also fixes another problem that I found :) The other issue is if I don't have that as true, when I enter edit mode, the default value gets cleared. I posted that issue on another thread http://ko.infragistics.com/community/forums/t/73351.aspx
So I guess I'll keep that setting for now :)
That is correct, AlloCustomValue swaps functionality of igCombo-grid-editor from valueKey to textKey. I mentioned that in my earlier replies.You should keep in mind, that option will destroy functionality related to mapping/formatter key/id of data in cell/dataSource versus displayed text in grid. It means that combo-cell editor will show value in dataSource as it is and after end editirn it will update value in dataSource with text in combo, but not with possible valueKey.
Thanks for the sample Viktor. I must have missed something when setting up my formatter or column settings. I'll give it a try.
As an alternative, I found that setting the AllowCustomValue to true when setting the combo editor actually overrides this behavior. So, when I have that setting to true, when the edit mode ended, I see the TextKey displayed in the grid instead of the ValueKey.
I attached Mvc project for you.
That creates igGrid, which dataSource has 2 numeric columns Product and SlaveProduct.The combo editor in Product column has dataSource, which contains Key/ID of a product and text displayed in grid.The combo editor in SlaveProduct column has dataSource, which contains Key/ID and text displayed in grid. The records in that dataSource contains all possible values in that column.In order to show text in Product and SlaveProduct, which correspond to keys/ids, the columnSettings of grid sets the formatters.All codes related to server are located in GridModel2.cs. All those codes can be moved directly into view or controller.
In order to initialize maps for formatters, the values passed from server are used. Initialization is lazy (function initMaps) and it happens on first request to render. Similar initialization may be implemented on initialization of page or on other events.All javascript codes are located in ViewPage2.aspx. They have comments, which explain all actions and flow of logic. The dataSource of main combo (Product column) is permanent.The dataSource of slave combo (SlaveProduct column) is dynamic and it is updated on startEdit and on selection change in main combo. The instant sub/filtered dataSource is defined by records in original dataSource of combo used by SlavePoduct. The specific desired records are extracted using a map or indexes. For example, if value in main Product column is equal to 0, then dataSource for slave combo uses only original records 0,1,2,3. If value in main Product is 1, then slave combo uses records 4,5, etc.The synchronization of combos within addNewRow is supported as well.
In order to test that application, you will need to adjust reference to Infragistics.Web.Mvc.dll in csproj and web.config files to dll availiable on your machine. You also should adjust references to css/js resources in ViewPage2.aspx to point to files on your machine. If you create IIS VirtualDirectory with name ig_ui12.2, which points to directory where infragistics's js/css files are located, then project will run as it is.
Let me know if you have any further questions.
Hey guys,
Quick update, I couldn't make that solution to work. For some reason, that lookup function gets called twice when the edit ended which reverted back my selection in the combo box to the old one.
What did work for me was on editRowEnded I call the 'updateRow' to update columns that I need to update. Using this I don't need to create combo mapping for my combo controls.