View Full Version : Geting the value of a cell with variable columns
Lezard Valeth
07-19-2006, 08:48 PM
well this might be easier but here's the thing, i have a dataGrid but its nota a normla one, intested of adding lines when you click in the button i created it add's columns, but im having a problem, i need to get the value of a cell, but since there's no default name for the columns i dont know how to get the especific value i want.
ps: there's only one line so itemIndex will always be 0
Assertnfailure
07-19-2006, 09:00 PM
I'm not sure what you're trying to do. It sounds like you're asking how to communicate with a class you built yourself? o.O I built something that sounds like it might be similiar to what you're doing:
//DATATABLE MODEL
//Stores an array of elements in an abstract table layout
//created by Steven Schelter (assertnfailure@gmail.com)
class odm.models.DataTable extends Array{
//externally-defined parameters
private var _rowMax:Number = null;
private var _colMax:Number = null;
//local parameters
//private var elementlist:Array;
//CONSTRUCTOR
//@param:Array (OPTIONAL) = array of elements to store in the table
public function DataTable(elements:Array){
super();
for(var i=0; i<elements.length; i++) this[i] = elements[i];
}
//GETTERS/SETTERS
//maximum number of rows allowed in table (null = infinite)
public function set rowMax(newval:Number):Void{
if(newval == undefined || newval < 1) newval = null;
_rowMax = newval;
}
public function get rowMax():Number{
return _rowMax;
}
//maximum number of columns allowed in table (null = infinite)
public function set colMax(newval:Number):Void{
if(newval == undefined || newval < 1) newval = null;
_colMax = newval;
}
public function get colMax():Number{
return _colMax;
}
//number of rows currently in the table
public function get rowLength():Number{
if(_colMax == null){
if(length > 0) return 1;
return 0;
}
return Math.ceil(length/_colMax);
}
//PUBLIC METHODS
//overwrites current element list with a new element list
//@param:Array = array of elements to overwrite existing array with
public function populate(elements:Array):Void{
clear();
for(var i=0; i<elements.length; i++) this[i] = elements[i];
}
//clears current element list
public function clear():Void{
while(length > 0) delete pop();
}
//pushes an element to the end of the table
//@param = element to push
//@return:Object = object with parameters "r" and "c" which indicate row and column of element added, respectively (returns null if table overflows)
public function push(element):Object{
if(_rowMax != null && (length+1)/_colMax > _rowMax) return null;
super.push(element);
return indexToCell(length-1);
}
//unshifts an element to the beginning of the table
//@param = element to unshift
//@return:Object = object with parameters "r" and "c" which indicate row and column of element added, respectively (returns null if table overflows)
public function unshift(element):Object{
if(_rowMax != null && (length+1)/_colMax > _rowMax) return null;
super.unshift(element);
return {r:0, c:0};
}
//splices the table at the designated coord space following the same method as Array.splice
//@param:Number = index of row to splice
//@param:Number = index of col to splice
//@param:Number (OPTIONAL) = Number of elements to remove
//@param(1..N) (OPTIONAL) = Any additional parameters will be inserted into the table as elements
//@return:Array = elements removed from the table
public function splice(row:Number, col:Number):Array{
return(super.splice.apply(this, [cellToIndex(row, col)].concat(arguments.slice(2))));
}
//PUBLIC METHODS
//removes all null elements from the data table
public function removeNulls():Void{
for(var i=0; i<length; i++){
while(i<length && this[i] == null){
super.splice(i, 1);
}
}
}
//retrieves an element from the table coord space
//@param:Number = index of the element's row
//@param:Number = index of the element's col
//@return = element in the coord space
public function getElement(row:Number, col:Number):Object{
return this[cellToIndex(row, col)];
}
//retrieves a row of elements from the table
//@param:Number = index of the row being retrieved
//@return:Array = array of elements in the row
public function getRow(rowIndex:Number):Array{
var sublist:Array = new Array();
var firstIndex:Number = cellToIndex(rowIndex, 0);
var lastIndex:Number = cellToIndex(rowIndex, _colMax);
for(var i=firstIndex; i<lastIndex; i++){
if(this[i] == undefined) break;
sublist.push(this[i]);
}
return sublist;
}
//converts a cell row/column position to an index value
//@param:Number = row value
//@param:Number = column value
//@return:Number = index value
public function cellToIndex(row:Number, col:Number):Number{
if(_colMax == null) return col;
return row*_colMax+col;
}
//converts an index value to a cell row/column position
//@param:Number = index value
//@return:Object = object of r=row and c=column
public function indexToCell(index:Number):Object{
if(_colMax == null) return {row:0, col:index};
var row:Number = Math.floor(index/_colMax);
var col:Number = index%_colMax;
return {r:row, c:col};
}
//DEBUG METHODS
//traces out each row of the data table
public function traceElements():Void{
for(var r=0; r<rowLength; r++){
trace(getRow(r));
}
}
}
In mine, you can retrieve an element from a specific location by calling:
var element:Object = myDataTable.getElement(row, col);
Lezard Valeth
07-19-2006, 09:20 PM
o.O amazing class but its not like this my bad for having such a poor english. let me try to make it clear.
i already have the datagrid component, it starts with 3 columns wich will never desapear, but if the user wants he can add more columns.
the problem is since i am not a shaman or something i dont know what is the name he will put in the column and to get the data i normaly use the column name .
what i want to know is:
how can i get the values of the especific column if i dont know the name?
Lezard Valeth
07-20-2006, 02:27 PM
still needing help so **up**
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.