I have a ListGridField that displays values from a valueMap. If the values in the valueMap change, what is the best way to refresh the ListGridField to display the updated values without calling setFields and then markForRedraw on the entire grid? When I call setFields and then markForRedraw on the entire grid, it has the effect of un-doing any user customizing of the grid such as resizing columns or show/hide column actions.
Perfect, it looks like this just became public with 5.7 so I didin’t realize it was there. Would it make sense to expose this field for ListGridField as well? I didn’t think to look at ListGrid for this since I thought it should be part of ListGridField. Either way, thanks. That is just what I needed.
Good idea - we’ll add a link from the ListGridField.valueMap docs to ListGrid.setValueMap()
Thanks
Hi there,
I have a form that defines a valueMap but also uses pickListFields per your instructions in this post: http://forums.smartclient.com/showthread.php?t=364&highlight=valueMap
However,when I called setValueMap on this formItem, it doesn’t refresh the valuemap until I actually click on the formItem. Here is what the field looks like:
{name:"fundID",
change:"isc.Timer.setTimeout(\"findFundAssets();\",0);",
title:"<spring:message code="label.view.fund"/>",width:130, allowEmptyValue:true,emptyDisplayValue:"<spring:message code="label.all"/>", pickListFields:[{name:"fundID", emptyCellValue:"<spring:message code="label.all"/>", valueMap:fundValueMap}],valueMap:fundValueMap},
All other fields that don’t use pickListFields refresh fine with just calling setValueMap except this one. Any ideas how to refresh this properly?
You probably need to be calling setEditorValueMap if you are talking a pickList shown on an editor in the grid.
No, sorry for not clarifying. This is on a DynamicForm.
Hi senordhuff,
I don’t think you need to actually specify the valueMap within the pickListFields, it should be automatically picked up from the DataSource. If you avoid doing so, I think that may correct the problem with the valueMap sticking.
Hi, I tried that before but when I remove valueMap within the pickListFields, it is showing me the raw value in the list and not the Mapped value. I mentioned this in the last two posts here: http://forums.smartclient.com/showthread.php?t=364&highlight=valueMap
Sorry about that, I thought this was a databound pickList, in which case the valueMap would come from the DataSource.
Can you describe exactly the refresh you want to see - you have shown a pickList, then the pickList has been hidden, and at that point you setValueMap() but the value displayed in the SelectItem is not refreshing?
No problem.
We have a pickList and the values in the pickList are changed when the user makes an update, so we call setValueMap but the value in the SelectItem is not refreshing. If we then manually put focus on the SelectItem, it changes. But otherwise, it does not refresh. This is only an issue when we are using pickListFields. And, we are using pickListFields in order to display a blank value as “All” as described in the other post (http://forums.smartclient.com/showthread.php?t=364&highlight=valueMap)
I think a workaround of calling item.setValue(item.getValue()) would work.
Well, when the selected entry in the valueMap changes, it does refresh properly so that workaround doesn’t solve the problem. The problem is that it doesn’t refresh the display when an un-selected entry changes.
I also just noticed a second problem. If you add another entry to the valuemap and then call setValueMap() to include this new entry, it displays the id and not the mapped value. In this case , if I then select this new entry, it displays the correct value in the field but the drop-down list continues to show the id instead of the mapped value.
Sorry, we’re having trouble following - what’s an un-selected entry? Do you think you could just provide some sample code?
Sorry about that, let me try to do a better job explaining.
So, as I mentioned we have a field on a Dynamic Form defined as follows. The dynamic Form is “findFAForm”:
{name:"fundID",
change:"isc.Timer.setTimeout(\"findFundAssets();\",0);",
title:"<spring:message code="label.view.fund"/>",width:130, allowEmptyValue:true,emptyDisplayValue:"<spring:message code="label.all"/>", pickListFields:[{name:"fundID", emptyCellValue:"<spring:message code="label.all"/>", valueMap:fundValueMap}],valueMap:fundValueMap},
We are using the pickListFields approach based on your feedback in the other thread (http://forums.smartclient.com/showthread.php?t=364&highlight=valueMap) in order to provide an “All” option as part of the valueMap.
So, let’s say that fundValueMap has the following items:
1: Fund A
2: Fund B
3: Fund C
There is another canvas in our application where the user can update the values in the FundValueMap.
Problem 1:
The user changes the FundValueMap so it now looks like this:
1: Fund A
2: Fund B
3: Fund C-Edit
The user changed FundID 3 as you see above. Then the following code is executed in the callback to that save operation…
//this callback updates the fundValueMap and then updates all references
//to the fundValueMap
setFundValueMap(data);
findFAForm.setValueMap("fundID", fundValueMap);
If findFAForm.getValue(“fundID”)!=3, then the drop-down that displays for the fundID field on the findFAForm is not getting refreshed to show “Fund C-Edit” and continues to show “Fund C”. If I put my cursor in the drop-down and select “Fund C”, it then changes to “Fund C-Edit”. But, I want it to refresh without this manual focus on the field. If findFAForm.getValue(“fundID”)== 3, it does refresh and shows “Fund C-Edit”. So, I’m trying to figure out how to get the drop-down to refresh in that scenario when it is not the currently selected value.
Problem 2:
The user adds a new item to the valueMap so it now looks like this:
1: Fund A
2: Fund B
3: Fund C-Edit
4: Fund D
The user added FundID 4 as you see above. Then the following code is executed in the callback to that save operation…
//this callback updates the fundValueMap and then updates all references
//to the fundValueMap
setFundValueMap(data);
findFAForm.setValueMap("fundID", fundValueMap);
In this scenario, the fundID field on findFAForm displays “4” in the drop-down instead of “Fund D”.
Does that help clarify the problems I’m having?
Hi Senordhuff
Thanks for the excellent clarification
Basically I see 2 problems here:
1: Currently the emptyDisplayValue for a select item isn’t displayed in the empty entry in the item’s drop-down-list. This is the issue discussed in this other thread http://forums.smartclient.com/showthread.php?t=364&highlight=valueMap.
We actually have local code to resolve this underlying issue but it didn’t make it into the 6.0 release - we’ll make sure it gets into our next release.
2: To workaround the first issue, you’re declaring explicit pickList fields for your select item (with an emptyCellValue, and a static valueMap object). However you’re finding that the valueMap on the drop down isn’t being updated when you call setValueMap() for the form item as a whole.
You should be able to fix this by simply re-setting the pickListFields for the item when you modify the valueMap, using ‘setProperties()’.
Try adding this override to your form item’s setValueMap method:
setValueMap : function (map) {
// call 'super' to set the valueMap on the form item
this.Super("setValueMap", arguments);
// re-set the pickListFields on the form item
this.setProperties({pickListFields:[{
name:"fundID", emptyCellValue:"ALL",
valueMap:map
}]
}
Then when you call ‘setValueMap’ on the form item, the valueMap will be updated on both the item and in the pickList, and the next time the drop down is shown, the updated valueMap will be displayed
Of course once we make the fix for the underlying issue public, the explicit pickListFields specification can go away which will simplify your code somewhat
As always - let us know if you hit any problems
Thanks
Isomorphic Software
Thank you very much, that resolved both of my issues. I figured that I needed to update the valueMap on the pickListFields but wasn’t sure exactly how to do it and I see I needed to use setProperties.
The code sample you provided needed a little bit of tweaking. It was missing the ending “})” for setProperties. Here is the final product:
setValueMap : function (map) {
this.Super("setValueMap", arguments);
this.setProperties({
pickListFields:[{
name:"fundID", emptyCellValue:"<spring:message code="label.all"/>",
valueMap:map
}]
})
}
Hi,
I have a related problem.
I enter values in one ListGrid. Those values are presented in another ListGrid as a dropdown list.
The new values appear, but they appear at the bottom of the list.
My client gets confused, since the new values don’t appear where they expect them alphabetically.
How can I have the new entry appear in the correct spot, alphabetically?
Or how do I get them to resort?
Thanks,
Mike
Hi Mike,
If you specify a sort order for the PickList (via pickListProperties.sortFieldNum) you should see the new values automatically slot into the right order according to the specified sort.
What about for a select list inside a ListGrid? (editorType: “select”)
isc.ListGrid.create({
ID:"magazineList",
dataSource:"magazineRestDS",
dataProperties:{useClientFiltering:false},
fields:[
{name:"mag_name", title:"Title", showHover:true},
{name:"mag_number", title:"Number", showHover:true, width:75},
{name:"mag_contract_id", title:"Contract",
showHover:true,
editorType: "select",
optionDataSource:"contractRestDS",
autoFetchDisplayMap: true,
valueField:"contract_id",
displayField:"contract_name"},
{name:"mag_add_date", title:"Date Added", align:"center", showHover:true, canEdit:false}
],
alternateRecordStyles:true,
useCellEvents:true,
recordClick: "issueFindForm.findIssues(record.mag_id);",
selectionType:"single",
canEdit: true,
editEvent: "doubleClick",
showFilterEditor: false,
listEndEditAction: "done",
autoDraw:false
});