How to set combo box in grid cell initial display?
Hi,
We need a combo box in a cell grid with texts different from datas/values.
The code below works when selecting a value in the list: cell text and value are OK:
<img src="ftp://foxincloud.com/Screenshots/FIC/grid-combo-selection.png" />
However, after the initial grid load, the cells display datas/values instead of texts:
<img src="ftp://foxincloud.com/Screenshots/FIC/grid-combo-initial.png" />
How can the cells initially display texts instead of datas/values
We need a combo box in a cell grid with texts different from datas/values.
The code below works when selecting a value in the list: cell text and value are OK:
<img src="ftp://foxincloud.com/Screenshots/FIC/grid-combo-selection.png" />
However, after the initial grid load, the cells display datas/values instead of texts:
<img src="ftp://foxincloud.com/Screenshots/FIC/grid-combo-initial.png" />
How can the cells initially display texts instead of datas/values
var grd = new AW.UI.Grid;
grd.setRowCount(3);
grd.setColumnCount(3);
grd.setCellEditable(true);
grd.setCellTemplate (new AW.Templates.Combo, 2);
var texts, datas, values;
texts = ['AK','BC','CA','Co. Cork','DF','France','ID','IL','Lancashire','Lara','MT','NM','Nueva Esparta','OR','Québec','RJ','SP','Táchira','WA','WY'];
datas = values = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20'];
var cboFormat = AW.System.Format.subclass();
cboFormat.create = function(){ // attempt to create a specific format
var obj = this.prototype;
obj.dataToText = function(data){return texts[datas.indexOf(data)]};
obj.dataToValue = function(data){return data;}; // needed?
obj.textToValue = function(text){return text;}; // needed?
obj.textToData = function(text){return text;}; // needed?
obj.valueToData = function(value){return value;}; // needed?
obj.valueToText = function(value){return value;}; // needed?
};
// grd.setCellFormat (cboFormat, 2); // does not work: cell are no longer editable with this instruction
var lst = new AW.UI.List; // new AW.Templates.List useless because it has no setItem*() methods
lst.setItemCount(texts.length);
lst.setItemText(texts);
lst.setItemValue(values);
grd.setPopupTemplate(lst, 2);
grd.onCellValidated = function(text, col, row){
col = parseInt(col, 10);
if (col == 2){
console.log('col: ' + col + ', row: ' + row);
console.log('text: ' + text); // OK: read from texts above
var value = grd.getCellValue(col, row);
console.log('value: ' + value) // OK: read from values above
}
};
grd.setCellData([
['1','1','1']
, ['2','2','2']
, ['3','3','3']
]);
document.write(grd);
Thierry Nivelet (FoxInCloud)
February 12,