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
Ok, I think I need to get the whole product entity and map the column to the entity instead of the name..
and inside the lookup function check if the parameter coming in is a product object or productID, then based on that return Product.Name or the mapping value
There is a typo, the function name should be lookupProductName:
function lookupProductName(productID) { if(productID) return comboMapProduct[productID];}
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 ?
Hi Jeffrey,
Answers and example provided by Martin are correct.
I can add few things to help understand that aspect of igGrid architecture.The igGrid editor is used only for editing and it is not related to rendering. Minor options for rendering (like date/number formats, or suffix/prefix for value) can be handled by format option/property of grid-column. But full custom rendering is possible only by using formatter option of column. That member should be a function which returns string for a value in a cell. At this point application may provide any content. In case of igCombo value<->text, its implementation can be very simple: just return mapped value for a key. That map can be built on client using dataSource of combo coming from server (example of Martin), or it can have hard coded implementation, like in my attached example.
If dataSource of combo editor is provided by server within ComboEditorOptions, then only data related to Text/ValueKey is passed to client. That corresponds to enabled CompactData property of ComboModel. That property is designed to reduce size of data passed to client and it is not exposed by ColumnUpdatingComboEditorOptions.
By default the combo grid-editor-provider uses valueKey to exchange data between igCombo and igGridUpdating. In order to use textKey, an application should enable allowCustomValue of igCombo. In this case combo will allow to enter and pass to grid any value, but not only value defined by its dataSource.
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://es.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.