Earlier in this thread you raised this issue:
- When you have a databound SelectItem or ComboBoxItem with a displayField and valueField specified, selecting an item from the drop down list initially correctly shows the display-field value in the form item.
However when you force the drop down list to fetch new data (which can be done in various ways - in our test case we were re-sorting the pick-list data), you can lose the display value for the selected item, and start showing the underlying data value instead.
This turned out to be a bug - we’ve now fixed this, and the fix should be present in 7.0 final.
However I think you were seeing a separate issue as well -
Your code to modify the “Grids\Edit\Enter New Rows” sample has a couple of issues which should be corrected:
Firstly you’re setting optionDataSource / valueField / displayField on the editor (using editorProperties), not on the ListGridField. The ListGrid will need to know about these properties to perform mapping once you’ve performed a save of the edited row.
Secondly you’re using the same dataSource for the grid and optionDataSource for the editable field, which may cause unexpected behavior since by changing the record values, you’ll be changing the set of options that show up in the drop down list (they’re drawn from the same data-set).
There are cases where it makes sense to have a ListGridField’s optionDataSource match the dataSource of the grid (for example editing an employee/manager relationship - you may want to draw the list of possibly managers from another field in the same datasource) - but it doesn’t make sense in the example you posted, with the displayField matching the underlying fieldName, and the valueField being something else.
Here’s a quick demo showing how to make use of optionDataSource / displayField in a ListGridField. See if this helps clarify things:
isc.DataSource.create({
ID:"ds1",
clientOnly:true,
fields:[
{name:"f1", primaryKey:true},
{name:"f2"},
{name:"f3"}
],
testData:[
{f1:"1", f2:"Record 1", f3:"Description for Record 1"},
{f1:"2", f2:"Record 2", f3:"Description for Record 2"},
{f1:"3", f2:"Record 3", f3:"Description for Record 3"},
{f1:"4", f2:"Record 4", f3:"Description for Record 4"},
// show a record with a f2 value that matches a record from ds2's "a" field value
// This will be valueMapped across to the appropriate display value
{f1:"5", f2:"a5", f3:"Record 5 - f2 matches a record in ds2"}
]
});
isc.DataSource.create({
ID:"ds2",
clientOnly:true,
fields:[
{name:"a", primaryKey:true},
{name:"b"},
{name:"c"}
],
testData:[
{a:"a1", b:"ds2 Record 1", c:"Description for Record 1 on DS 2"},
{a:"a2", b:"ds2 Record 2", c:"Description for Record 2 on DS 2"},
{a:"a3", b:"ds2 Record 3", c:"Description for Record 3 on DS 2"},
{a:"a4", b:"ds2 Record 4", c:"Description for Record 4 on DS 2"},
{a:"a5", b:"ds2 Record 5", c:"Description for Record 5 on DS 2"}
]
});
// A listGrid demonstrating optionDataSource / valueMap
isc.ListGrid.create({
ID:"testGrid",
dataSource:"ds1",
height:200, width:300,
autoFetchData:true,
canEdit:true,
fields:[
{name:"f2", optionDataSource:"ds2", displayField:"b", valueField:"a",
editorProperties:{pickListFields:[{name:"a"}, {name:"b"}]}},
{name:"f3"}
]
});
// A button so you can see the underlying data value for field f2
isc.IButton.create({
top:250,
title:"Show Selected Record Values",
autoFit:true,
click:"isc.warn(isc.Log.echo(testGrid.getSelectedRecord()))"
})
Update: I think this may essentially “close this issue out” - it seems like you shouldn’t need to use formatCellValue() since the translation happens automatically as demonstrated in this example - however if you’re still having issues, please let us know
Thanks