While searching through the forum to see if I could find some information regarding a problem with value-formatting while using a "DynaScrollTable" I came across this response by Dario Crivelli in a thread regarding the
"addField" method:
@DarioCrivelli, Wrote: [...]
However, in the onChangingValuescallback (the place where formatting instructions can be given to the VisualTable ), the previous values of the updated fields are not available.
On the other hand, they are available in the onItemUpdate callback.
[...]
Out of curiosity, why did you chose to make the previous values available only in "onItemUpdate" and not in "onChangingValues"?
We actually are dealing with this "problem" on one of our sites at the moment. We have a "DynaScrollTable" receiving updates containing a timestamp, an identifier (string) and two decimal numbers. We need to format the numbers before displaying them (rounding decimal places, insert thousands separator - e.g. original value is "12345.6" and should be displayed as "12.345,600"), and it normally works like it should..
..but sometimes only one of the two numbers changes, so when our "onChangingValues"-function gets called I can't access the value that the unchanged field previously had, as "updateInfo.getFormattedValue("number2")" is "null". As we don't know the previous value we're not able to format it, and the unformatted value is displayed in the table.
Ideally I would write something like this in "onChangingValues":
[SYNTAX="JS"]
myDynaScrollTable.onChangingValues = function(domNode, updateInfo) {
//...
var number2 = updateInfo.getFormattedValue("number2");
if (updateInfo.getFormattedValue("number2") == null) {
// field unchanged, reuse previous value
number2 = updateInfo.getOldValue("number2");
}
// do some magic formatting to variable "number2"
updateInfo.setFormattedValue("number2", number2);
//...
}[/SYNTAX]
..but I don't have access to the old value in "onChangingValues". At the moment the only way I see to get it to work would be to add some logic to the "onItemUpdate"-function, check if there are fields that did not change, and then add the old values of those fields via "UpdateItemInfo.addField(...)", so that I have the old value available in "onChangingValues" - I can't format the respective field in the "onItemUpdate"-function as I can read the value but not write it back into the field ("addField()" can only be used to add extra fields).
I don't really like this "solution" as it looks to me to be quite inelegant, but I don't see any other solution - perhaps I'm missing something simple or obvious as I assume that this is not an unusual use-case, but looking through the
online documentation didn't give me some better idea yet.
Ideally, for an unchanged field, the table should just reuse the last set value of "setFormattedValue()" for the specific field, so my code could just ignore unchanged values, but the web client api doesn't seem to behave like this, at least on our site.
I also looked through the
Changelog for the Web Client SDK, to see if there was some change or bugfix that related to formatted values, but I did not find anything there, either.
Any idea or comment is appreciated.