Get from http://cwashington.netreach.net/depo/view.asp?Index=812&ScriptType=jscript:
It can be used like this:
function Recordset(arrFieldNames,arrData) {
this.Columns = arrFieldNames;
this.Data = arrData;
this.Columns.Count = this.Columns.length;
this.Record = 0;
this.AbsolutePosition = 1;
this.EOF = false;
this.BOF = false;
this.RecordCount = arrData.length;
this.Fields = Recordset_Fields;
this.Move = Recordset_Move;
this.MoveFirst = Recordset_MoveFirst;
this.MoveNext = Recordset_MoveNext;
this.MovePrevious = Recordset_MovePrevious;
this.MoveLast = Recordset_MoveLast;
this.AddNew = Recordset_AddNew;
this.Update = Recordset_Update;
this.Delete = Recordset_Delete;
this.CheckPosition = Recordset_CheckPosition;
this.CheckPosition();
}
function Recordset_Fields(x, debug) {
this.Record = this.AbsolutePosition-1;
if (isNaN(x*1)) {
for (var i=0; i<this.Columns.length; i++) if (this.Columns[i].toUpperCase() == x.toUpperCase()) return (new Field(this.Columns[i], this.Data[this.Record][i]));
} else if (x < this.Data[this.Record].length) {
return (new Field(this.Columns[x], this.Data[this.Record][x]));
}
alert("JS Recordset error: Item (" + x + ") not found.");
return (new Field(x, ""));
}
function Recordset_Move(i) {
this.Record += i-1;
this.AbsolutePosition += i;
this.CheckPosition();
}
function Recordset_MoveFirst() {
this.Record = 0;
this.AbsolutePosition = 1;
this.EOF = false;
this.BOF = false;
}
function Recordset_MoveNext() {
this.Record++;
this.AbsolutePosition++;
this.CheckPosition(0);
}
function Recordset_MovePrevious() {
this.Record--;
this.AbsolutePosition--;
this.CheckPosition(1);
}
function Recordset_MoveLast() {
this.Record = this.Data.length-1;
this.AbsolutePosition = this.Data.length;
this.EOF = false;
this.BOF = false;
}
function Recordset_AddNew(xFields, xValues) {
this.Record = this.Data.length;
this.AbsolutePosition = this.Data.length+1;
this.Data[this.Data.length] = new Array(this.Columns.length);
this.RecordCount = this.Data.length;
if (xFields) this.Update(xFields, xValues);
}
function Recordset_Update(xFields, xValues) {
this.Record = this.AbsolutePosition-1;
if (typeof(xFields) == "string") {
for (var i=0; i<this.Columns.length; i++) {
if (this.Columns[i].toUpperCase() == xFields.toUpperCase()) {
this.Data[this.Record][i] = xValues + "";
return true;
}
}
throw "JS Recordset error: Item (" + xFields + ") not found.";
} else {
if (xFields.length) for (var i=0; i<xFields.length; i++) this.Update(xFields[i], xValues[i]);
return true;
}
}
function Recordset_Delete() {
this.Data = this.Data.remove(this.Record);
this.RecordCount = this.Data.length;
this.Record--;
this.AbsolutePosition--;
this.CheckPosition();
}
function Field(strName, strValue) {
this.Name = strName;
this.Value = strValue;
}
function Recordset_CheckPosition(iDirection) {
switch(iDirection) {
case 0 : // forward - check EOF
if (this.Record == this.Data.length) this.EOF = true;
else this.EOF = false;
break;
case 1 : // backward - check BOF
if (this.Record == -1) this.BOF = true;
else this.BOF = false;
break;
default :
if (this.Record == this.Data.length || this.Data.length == 0) this.EOF = true;
else this.EOF = false;
if (this.Record == -1 || this.Data.length == 0) this.BOF = true;
else this.BOF = false;
}
}
this.Columns = arrFieldNames;
this.Data = arrData;
this.Columns.Count = this.Columns.length;
this.Record = 0;
this.AbsolutePosition = 1;
this.EOF = false;
this.BOF = false;
this.RecordCount = arrData.length;
this.Fields = Recordset_Fields;
this.Move = Recordset_Move;
this.MoveFirst = Recordset_MoveFirst;
this.MoveNext = Recordset_MoveNext;
this.MovePrevious = Recordset_MovePrevious;
this.MoveLast = Recordset_MoveLast;
this.AddNew = Recordset_AddNew;
this.Update = Recordset_Update;
this.Delete = Recordset_Delete;
this.CheckPosition = Recordset_CheckPosition;
this.CheckPosition();
}
function Recordset_Fields(x, debug) {
this.Record = this.AbsolutePosition-1;
if (isNaN(x*1)) {
for (var i=0; i<this.Columns.length; i++) if (this.Columns[i].toUpperCase() == x.toUpperCase()) return (new Field(this.Columns[i], this.Data[this.Record][i]));
} else if (x < this.Data[this.Record].length) {
return (new Field(this.Columns[x], this.Data[this.Record][x]));
}
alert("JS Recordset error: Item (" + x + ") not found.");
return (new Field(x, ""));
}
function Recordset_Move(i) {
this.Record += i-1;
this.AbsolutePosition += i;
this.CheckPosition();
}
function Recordset_MoveFirst() {
this.Record = 0;
this.AbsolutePosition = 1;
this.EOF = false;
this.BOF = false;
}
function Recordset_MoveNext() {
this.Record++;
this.AbsolutePosition++;
this.CheckPosition(0);
}
function Recordset_MovePrevious() {
this.Record--;
this.AbsolutePosition--;
this.CheckPosition(1);
}
function Recordset_MoveLast() {
this.Record = this.Data.length-1;
this.AbsolutePosition = this.Data.length;
this.EOF = false;
this.BOF = false;
}
function Recordset_AddNew(xFields, xValues) {
this.Record = this.Data.length;
this.AbsolutePosition = this.Data.length+1;
this.Data[this.Data.length] = new Array(this.Columns.length);
this.RecordCount = this.Data.length;
if (xFields) this.Update(xFields, xValues);
}
function Recordset_Update(xFields, xValues) {
this.Record = this.AbsolutePosition-1;
if (typeof(xFields) == "string") {
for (var i=0; i<this.Columns.length; i++) {
if (this.Columns[i].toUpperCase() == xFields.toUpperCase()) {
this.Data[this.Record][i] = xValues + "";
return true;
}
}
throw "JS Recordset error: Item (" + xFields + ") not found.";
} else {
if (xFields.length) for (var i=0; i<xFields.length; i++) this.Update(xFields[i], xValues[i]);
return true;
}
}
function Recordset_Delete() {
this.Data = this.Data.remove(this.Record);
this.RecordCount = this.Data.length;
this.Record--;
this.AbsolutePosition--;
this.CheckPosition();
}
function Field(strName, strValue) {
this.Name = strName;
this.Value = strValue;
}
function Recordset_CheckPosition(iDirection) {
switch(iDirection) {
case 0 : // forward - check EOF
if (this.Record == this.Data.length) this.EOF = true;
else this.EOF = false;
break;
case 1 : // backward - check BOF
if (this.Record == -1) this.BOF = true;
else this.BOF = false;
break;
default :
if (this.Record == this.Data.length || this.Data.length == 0) this.EOF = true;
else this.EOF = false;
if (this.Record == -1 || this.Data.length == 0) this.BOF = true;
else this.BOF = false;
}
}
It can be used like this:
var rs = new Recordset(["field1", "field2"],[["field1row1data", "field2row1data"], ["field1row2data", "field2row2data"]]);