thanks carlos,
Your examples helped quite abit. Here is the resulting code.
Hope it helps everyone. Its an example of adding deleting and change row data from a CSV source.
Please let me know if I can refine the code in anyway. ( i added a few comments to give you an idea of my thoughts).
<html>
<head>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>
#myGrid { width: 600px; margin: 0px; padding: 0px}
#myGrid .aw-grid-row {height: 16px; border-bottom: 1px solid #C6C6C6; }
#myGrid .aw-alternate-even .aw-column-0 {background: #E0E0E0;}
#myGrid .aw-alternate-odd .aw-column-0 {background: #E0E0E0;}
#myGrid .aw-alternate-even {background: #E7E7D6;}
#myGrid .aw-alternate-odd {background: #F7F3E7;}
#myGrid .aw-cells-selected {background: default; color: black;}
#myGrid .aw-column-0 {width: 50px; border-right: 1px solid #848484; cursor:default;}
#myGrid .aw-column-1 {width: 110px; border-right: 1px solid #C6C6C6; cursor:hand; }
#myGrid .aw-column-2 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-3 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-4 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-5 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-6 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-7 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-8 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-9 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-10 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-column-11 {width: 70px; border-right: 1px solid #C6C6C6; cursor:hand; text-align: right; }
#myGrid .aw-grid-headers {font-weight: bold; cursor:pointer;}
#myGrid .aw-grid-footers {background: #E7E7D6; border-top: 1px solid #C6C6C6; border-bottom: 1px solid #C6C6C6; }
#myGrid .aw-grid-footers .aw-column-0 {background: #E0E0E0;}
#myInpt {width:120%; height:100%; margin:-2px; margin-left:-4px;}
</style>
<script>
new AW.CSV.Table;
AW.CSV.Table.prototype.response = function(text){
this._rows = text.split(/\r*\n/);
this._data = [];
if (this.$owner) {
var sortCol = this.$owner.getSortColumn();
var sortDir = this.$owner.getSortDirection(sortCol);
this.$owner.clearSelectionModel();
this.$owner.clearSortModel();
this.$owner.clearRowModel();
this.$owner.setRowCount(this.getCount());
this.$owner.refresh();
if (sortCol>= 0) obj.sort(sortCol, sortDir);
}
};
var reloadid
var myCODE = ""
var myCODEc = 0;
var myCODEr = 0;
var myURL = "http://au.finance.yahoo.com/d/quotes.csv?s=";
var myCODES = "BHP.AX,TLS.AX,CBA.AX,NAB.AX,WBC.AX,AXA.AX,RIO.AX,AGL.AX,ALL.AX,AMP.AX,ANZ.AX,AMC.AX,BIL.AX,BLD.AX,CCL.AX,CML.AX";
var myCOLS = "&f=snc6p2l1b3b2ohgt1d1&e=.csv";
var myHeaders = ["Code", "Name", "+/-", "%", "Last", "Bid", "Ask", "Open", "High", "Low", "Time", "Date"];
var myFormats = [ str, str, num, num, num, num, num, num, num, num, str, str];
var myFooters = [];
var tbl = new AW.CSV.Table;
var obj = new AW.Grid.Extended;
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
var htm = new AW.Formats.HTML;
var edt = new AW.UI.Input;
tbl.setURL(myURL+myCODES+myCOLS);
tbl.request();
obj.setCellModel(tbl);
obj.setHeaderText(myHeaders);
tbl.setFormats(myFormats);
obj.setColumnCount(myHeaders.length);
obj.setId("myGrid");
obj.setCellEditable(false);
obj.setCellEditable(true , 0);
obj.setHeaderCount(1);
obj.setSelectorVisible(false);
obj.setVirtualMode(false);
obj.setFooterVisible(true);
obj.setFooterText(myFooters);
obj.setFooterCount(1);
obj.setFooterHeight(16);
edt.setId("myInpt");
document.write(obj);
obj.onCellTextChanged=function(val,col,row){
myCODE = val;
myCODEc = col;
myCODEr = row;
}
obj.onCellValueChanged=function(val,col,row){
if (col==myCODEc && row==myCODEr) {
myCODE = addCodeClean(myCODE);
if (myCODES.indexOf(myCODE)>=0) myCODE="";
if (myCODE != val) {
updateCodes(myCODE,col,row);
reload(0);
}
}
}
obj.onCellMouseDown = function(event, column, row){ if (column>0) dragstart(event) };
obj.onCellMouseUp = function(event, column, row){ dragstop() };
obj.onControlMouseUp = function(event){ dragstop() };
obj.onFooterClicked = function(event,index){
obj.setFooterText(edt,0);
obj.getFootersTemplate(0,0).refresh();
var edit = edt.element().getElementsByTagName("input")[0];
edit.focus();
edit.select();
AW.attachEvent(edit, "onblur", addCode);
AW.attachEvent(edit, "onkeydown", addCodeKey);
};
function reload(i){
var now = new Date();
tbl.setURL(myURL+myCODES+myCOLS);
tbl.request();
for(var i=2;i<obj.getColumnCount();i++) obj.getCellTemplate(i).refresh();
var now1 = new Date();
var load = (now1-now) / 1000;
window.status = "Last Response: " + now1 + " ... Live Response Time: " + load + " secs";
if (i==0) return reloadid;
reloadid=setTimeout('reload()', 5000);
}
function addCode(){
var edit = edt.element().getElementsByTagName("input")[0];
myCODE = addCodeClean(edit.value);
AW.detachEvent(edit, "onblur", addCode);
obj.setFooterText("",0);
obj.getFootersTemplate(0,0).refresh();
if (myCODES.indexOf(myCODE)<0) {
myCODES = myCODES + "," + myCODE;
reload(0);
}
}
function addCodeKey(e){
var code = event.keyCode;
if (code == 13) addCode();
}
function addCodeClean(c){
c = c.toUpperCase();
if (c.indexOf(".")<0 && c.length>0) return c+".AX";
else return c;
}
function updateCodes(v,c,r){
str = "";
for (var x=0;x<obj.getRowCount();x++) {
if (c==0 && r==x) str = str + "," + v;
else str = str + "," + obj.getCellText(0,x);
}
myCODES = str.substr(1);
}
function colorCell(o,n,x,y) {
if (o) { if (n > o[x]) obj.getCellTemplate(x, y).setStyle("background", "#C0F8C0");
if (n < o[x]) obj.getCellTemplate(x, y).setStyle("background", "#F8C0C0"); }
}
var dragapproved=false
var offsetx, offsety, tmpx, tmpy, maxx, maxy
function dragstart(e){
dragapproved=true;
offsetx=event.clientX;
offsety=event.clientY;
tmpx=obj.getScrollLeft();
tmpy=obj.getScrollTop();
maxx=obj.getScrollWidth() - document.getElementById("myGrid").offsetWidth + 18;
maxy=obj.getScrollHeight() - document.getElementById("myGrid").offsetHeight + 18;
if (document.getElementById("myGrid")) document.getElementById("myGrid").onmousemove=dragdrop
}
function dragdrop(e){
if (dragapproved&&event.button==1){
x=tmpx+offsetx-event.clientX
y=tmpy+offsety-event.clientY
}
if (x<0)x=0;
if (y<0)y=0;
if (x>maxx)x=maxx;
if (y>maxy)y=maxy;
obj.setScrollLeft(x);
obj.setScrollTop(y);
}
function dragstop(){
dragapproved=false;
if (document.getElementById("myGrid")) document.getElementById("myGrid").onmousemove=null;
}
</script>
<p></p>
<input type="button" value="refresh" onclick="reload()"/>
<input type="button" value="stop" onclick="clearTimeout(reloadid);"/><br/>
<p id="info" name="info" style="font-family:arial;font-size:12px">
Double click on a code and change it to change the item. <br>
Double click on a code and delete the text and it will delete the line. <br>
Click on the footer and add a code it will add a line to the list. <br>
Click and drag on the body data to scroll.
</p>
<p id="info2" name="info2" style="font:courier;font-size:10px">
</p>
</body>
</html>