Usually an item subscribed in COMMAND mode is displayed through a
DynaMetapushTable. However if your application directly takes care of the view, then a
NonVisualTable can be employed.
This post briefly shows how to modify the
Portfolio Demo in order to use a NonVisualTable.
The last lines of the PortfolioDemo index.html page will become:
[highlight=javascript]
/////////////////////////////////table handler
var table = new NonVisualTable("portfolio", schema, "COMMAND");
table.setSnapshotRequired(true);
// the following settings were used to control the behaviour
// of the DynaMetapushTable; with NonVisualTable, all
// formatting, paging and sorting stuff, if required,
// should be managed by custom code
// table.setPushedHtmlEnabled(false);
// table.setClearOnDisconnected(true);
// table.onChangingValues = formatValues;
// table.setMaxDynaRows("unlimited");
// table.setMetapushFields(2, 1);
// table.setMetapushSort(3, direction);
table.onItemUpdate = myUpdateHandler;
lsPage.addTable(table, "info");
Some code in the original index.html is no longer needed, because it is related to the DynaMetapushTable. In particular, the <TABLE> element has to be replaced with the custom GUI object and the "changeSort" and "formatValues" functions (together with their helper functions: "formatTime", "formatDecimal" and "convertCommaToDot") can be removed.
A new "myUpdateHandler" function, on the other hand, is now needed. It may be coded in the following way:
[highlight=javascript]
function myUpdateHandler(item, updateValues) {
// item should be always 1
// updateValues is of type "UpdateItemInfo"
// (see the JSDocs for details)
var commandField = 2;
// the "command" field is the second field
// on the specified schema
var keyField = 1;
// the "key" field is the first field
// on the specified schema
var command = updateValues.getNewValue(commandField);
var key = updateValues.getNewValue(keyField);
if (command == "ADD") {
addRowOnMyGUI(key, updateValues);
} else if (command == "UPDATE") {
updateRowOnMyGUI(key, updateValues);
} else if (command == "DELETE") {
deleteRowOnMyGUI(key);
}
}
The new "addRowOnMyGUI", "updateRowOnMyGUI" and "deleteRowOnMyGUI"
functions should be added. The supplied "updateValues" object can be used in order to find the current values of the subscribed fields ("stock", "price", "qty", "cval" and "time"), by invoking on it the "getNewValue" method, with parameter 3, 4, 5, 6 or 7.