Dario Crivelli
The tutorial demo page does not make use of "
addField". I suppose you are using the StockList demo page, which does take advantage of this method in order to add "extra fields", which are computed for each update, based on the other field values. The StockList demo uses extra fields to implement the arrows and as helper fields to implement the cell colouring.
Extra fields can be identified by names or by numbers; in the latter case, the numbers must be greater than the number of subscribed fields. Unfortunately, the StockList demo page code names the extra fields with numbers and uses the first numbers available (i.e. 14, 15 and 16). Admittedly, this is a bad choice and as soon as the number of subscribed fields is increased (which is your case), the numbers used are no longer allowed.
So, before adding the support for your new fields in the HTML page, you should change the numbers used in the various "addField" calls; you can use 114, 115 and 116, for instance. Note that the same changes should also be made in all places in which the extra fields are used, that is inside the "formatValues" method and in some cells.
Dario
tuongkha
Thanks Dario, can u explain more about java script code inside default.html?
---- StockList demo code. File "default.html" ------
var redColor = "#f8b87a";
var greenColor = "lightgreen";
function updateItem(item, updateInfo) {
if (updateInfo == null) {
return;
}
//My understand : if column pct_change has value changed, if the value > -1 show quotes_down.gif image, else show quotes_up.gif image.
In function updateInfo.addField(16, imgDown) , i can use 114, 115, 116 like u said and changed to addField(116, imgDown). Is it correct?
if (updateInfo.isValueChanged(3)) {
var val = updateInfo.getNewValue(3);
if (val.indexOf("-") > -1) {
updateInfo.addField(16,imgDown);
} else {
updateInfo.addField(16,imgUp);
}
}
var oldLast = updateInfo.getOldValue(1);
var newColor;
if (oldLast == null) { //first update for this item
updateInfo.addField(14,greenColor,true);
//no fade for snapshot
if (doFade) {
updateInfo.addField(15,"OFF",true);
}
} else if (updateInfo.isValueChanged(1)) {
//at least second update
//My understand : if column pct_change has value changed, if the new value > the old value, set color = green, else set color = red. Is it correct?
if (oldLast > updateInfo.getNewValue(1)) {
updateInfo.addField(14,redColor,true);
} else {
updateInfo.addField(14,greenColor,true);
}
if (doFade) {
updateInfo.addField(15,"ON",true);
}
}
}
---------
function formatValues(item, itemUpdate) {
if (itemUpdate == null) {
return;
}
// itemUpdate.getServerValue(15) == "ON" --> What does it means?
if (doFade) {
if (itemUpdate.getServerValue(15) == "ON")
{
itemUpdate.setHotToColdTime(300); --> i don't understand. }
}
itemUpdate.setHotTime(600);
if (itemUpdate.getServerValue(13) == "inactive") {
carryBackUnchanged(itemUpdate); --> i don't understand here
itemUpdate.setRowAttribute("#808080","#808080","color");
} else {
// itemUpdate.getFormattedValue(13) --> what does it means?
if (itemUpdate.getFormattedValue(13) != null) {
carryBackUnchanged(itemUpdate);
itemUpdate.setRowAttribute("#000000","#000000","color");
itemUpdate.setAttribute(12,"#000080","#000080","color");
}
//choose the backgroundColor
var backC = (item % 2 == 1) ? "#eeeeee" : "#ddddee";
var backH = itemUpdate.getServerValue(14);
itemUpdate.setRowAttribute(backH,backC,"backgroundColor");
//choose the "change" field stylesheet
var newChng;
// i don't understand code below
if ((newChng = itemUpdate.getFormattedValue(3)) != null) {
var hotTxtCol = (newChng.charAt(0) == '-') ? "#dd0000" : "#009900";
itemUpdate.setAttribute(3,"black",hotTxtCol,"color");
itemUpdate.setAttribute(3,"bold","bold","fontWeight");
}
itemUpdate.setAttribute(12,backC,backC,"backgroundColor");
}
tuongkha
Thanks Dario, like u said : extra field 16, If I change the field to 116 :
--- stocklist demo, default.html ----
function updateItem(item, updateInfo) {
if (updateInfo == null) {
return;
}
if (updateInfo.isValueChanged(3)) {
var val = updateInfo.getNewValue(3);
if (val.indexOf("-") > -1) {
updateInfo.addField(116,imgDown); } else {
updateInfo.addField(116,imgUp);
}
}
...
}
I should also change :
-- stocklist demo code, default.html -----
<script>
for (var i = 1; i <= 15; i++) {
var suff = (i % 2 == 1) ? "A" : "B";
document.write('<tr class="lscold'+suff+'">');
document.write('<td nowrap style="text-align: left"><div class="stockname'+suff+'" source="lightstreamer" table="1" item="'+i+'" field="12">Loading...</div></a></td>');
document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="1">-</div></td>');
document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="116">-</div></td>');
}
</script>
Is it correct?
And extra field 14, if i change the field to 114, I have to do :
---- stock list demo code, default.html ----
function updateItem(item, updateInfo) {
...
if (oldLast == null) { //first update for this item
updateInfo.addField(114,greenColor,true); //no fade for snapshot
if (doFade) {
updateInfo.addField(15,"OFF",true);
}
} else if (updateInfo.isValueChanged(1)) {
//at least second update
if (oldLast > updateInfo.getNewValue(1)) {
updateInfo.addField(114,redColor,true);
} else {
updateInfo.addField(114,greenColor,true);
}
if (doFade) {
updateInfo.addField(15,"ON",true);
}
}
and changed :
function formatValues(item, itemUpdate) {
....
//choose the backgroundColor
var backC = (item % 2 == 1) ? "#eeeeee" : "#ddddee";
var backH = itemUpdate.getServerValue(114);
itemUpdate.setRowAttribute(backH,backC,"backgroundColor");
}
-----------
Is it correct ?
--------------------
But in my code, i have a global variable declaration, and extra field identified by names, not by numbers, something like this :
////////////////Global var declaration
var group = ["item1", "item2", "item3", "item4","item5", "item6", "item7", "item8","item9", "item10", "item11", "item12","item13", "item14", "item15", "item16", "item17", "item18", "item19", "item20", "item21", "item22", "item23", "item24", "item25", "item26", "item27", "item28", "item29", "item30"];
var schema = ["last_price", "time", "pct_change","bid1", "bid2", "bid3", "bid1vol", "bid2vol", "bid3vol", "ask1","ask2", "ask3", "ask1vol", "ask2vol", "ask3vol", "min", "max","ref_price", "open_price", "stock_name", "ceiling", "floor", "lastVal", "lastVol", "close_price", "close_vol"];
var newTable = new OverwriteTable(group, schema,"MERGE");
-----
<script>
for (var i = 1; i <= 30; i++)
{
var suff = (i % 2 == 1) ? "A" : "B";
document.write('<tr class="lscold'+suff+'">');
document.write('<td> </td>');
document.write('<td class="stockname'+suff+'"><div source="lightstreamer" table="list" item="'+i+'" field="stock_name"> - </div></td>');
document.write('<td><div source="lightstreamer" table="list" item="'+i+'" field="ref_price"> - </div></td>');
...
}
</script>
---
I can change in updateItem() function something like this?
function updateItem(item, updateInfo) {
if (updateInfo == null) {
return;
}
if (updateInfo.isValueChanged("pct_change")) {
var val = updateInfo.getNewValue("pct_change");
if (val.indexOf("-") > -1)
{
updateInfo.addField("pct_change",imgDown); }
else
{
updateInfo.addField("pct_change",imgUp);
}
...
}
I mean I can used the name in updateItem.addField() function, not using the numbers?