<html>
<head>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>
</style>
<script>
var MyTable = AW.HTTP.Request.subclass();
MyTable.create = function(){
var obj = this.prototype;
obj._data = []; // data array
obj._min = -1; // min requested index
obj._max = -1; // max requested index
obj._loading = false; // request state
// returns cell data
obj.getData = function(col, row){
if(this._data[row]){
return this._data[row][col];
}
// if data not is available - remember requested rows range
this._min = this._min < 0 ? row : Math.min(row, this._min);
this._max = this._max < 0 ? row : Math.max(row, this._max);
// schedule data request
if (!this._loading){
this._loading = true;
this.setTimeout(function(){
// initiates the data request
var startIndex = this._min > 20 ? this._min - 20 : 0;
var rowCount = this._max - this._min + 41;
// initialize http request object
this.setURL("..some request url..");
this.setParameter("startIndex", startIndex);
this.setParameter("rowCount", rowCount);
this.request();
}, 0);
};
// if data is not loaded - return empty string
return "";
}
// override with fake request method for demo purposes
obj.request = function(){
this.setTimeout(function(){
this.response("..returned data string..");
}, 500);
}
// callback to process returned data
obj.response = function(data){
if (!this._data.length){
this._data = [];
}
this._min = -1;
this._max = -1;
this._loading = false;
// for demo only, should take from the returned data
var startIndex = Number(this._startIndexParameter);
var rowCount = Number(this._rowCountParameter);
window.status = "Loaded rows " + startIndex + "-" + (startIndex+rowCount);
var i, j;
for (i=startIndex;i<startIndex+rowCount;i++){
this._data[i] = [];
for(j=0;j<20;j++){
// for demo only, should take from the returned data
this._data[i][j] = i + "." + j;
}
}
if (this.$owner){
this.$owner.setRowCount(1000); //should take from the returned data
this.$owner.refresh();
}
}
}
var table = new MyTable();
table.setParameter("startIndex", 0);
table.setParameter("rowCount", 50);
table.request();
var obj = new AW.UI.Grid;
obj.setColumnCount(10);
obj.setCellModel(table);
document.write(obj);
</script>
</body>
</html>
<html>
<head>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>
</style>
<script>
var MyTable = AW.HTTP.Request.subclass();
MyTable.create = function(){
var obj = this.prototype;
obj._data = []; // data array
obj._min = -1; // min requested index
obj._max = -1; // max requested index
obj._loading = false; // request state
// returns cell data
obj.getData = function(col, row){
if(this._data[row]){
return this._data[row][col];
}
// if data not is available - remember requested rows range
this._min = this._min < 0 ? row : Math.min(row, this._min);
this._max = this._max < 0 ? row : Math.max(row, this._max);
// schedule data request
if (!this._loading){
this._loading = true;
this.setTimeout(function(){
// initiates the data request
var startIndex = this._min > 20 ? this._min - 20 : 0;
var rowCount = this._max - this._min + 41;
// initialize http request object
this.setURL("index.php");
this.setParameter("offset", startIndex);
this.setParameter("limit", rowCount);
this.request();
}, 0);
};
// if data is not loaded - return empty string
return "";
}
// I figured out that this next piece has to be completely commented out for things to work
// override with fake request method for demo purposes
// obj.request = function(){
// this.setTimeout(function(){
// this.response("..returned data string..");
// }, 500);
// }
// callback to process returned data
obj.response = function(data){
if (!this._data.length){
this._data = [];
}
this._min = -1;
this._max = -1;
this._loading = false;
// this is here for debug to see what we get back
alert(data);
// How to process the XML into the right format?
// for demo only, should take from the returned data
var startIndex = Number(this._startIndexParameter);
var rowCount = Number(this._rowCountParameter);
window.status = "Loaded rows " + startIndex + "-" + (startIndex+rowCount);
var i, j;
for (i=startIndex;i<startIndex+rowCount;i++){
this._data[i] = [];
for(j=0;j<20;j++){
// for demo only, should take from the returned data
this._data[i][j] = i + "." + j;
}
}
if (this.$owner){
this.$owner.setRowCount(1000); //should take from the returned data
this.$owner.refresh();
}
}
}
var table = new MyTable();
// missing table.setURL ?
table.setParameter("offset", 0);
table.setParameter("limit", 50);
table.request();
var obj = new AW.UI.Grid;
obj.setColumnCount(10);
obj.setCellModel(table);
document.write(obj);
</script>
</body>
</html>
table.setURL("index.php");
This topic is archived.