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);
var items = {
'FR': 'France',
'DE': 'Germany',
'UK': 'United Kingdom'
}
var format = new AW.System.Format();
format.valueToText = function(value){
return items[value];
}
obj.setCellFormat(format, 1);
var data = [
['abc', 'FR'],
['def', 'UK']
];
var items = {
'FR': 'France',
'DE': 'Germany',
'UK': 'United Kingdom'
}
var itemText = [], itemValue = [], itemLookup = {}, i;
for(i in items){
itemText.push(items[i]);
itemValue.push(i);
itemLookup[items[i]] = i;
}
var list = new AW.UI.List;
list.setItemText(itemText);
list.setItemCount(itemText.length);
list.focus = function(){};
var format = new AW.System.Format();
format.valueToText = function(value){
return items[value];
}
var obj = new AW.UI.Grid;
obj.setColumnCount(2);
obj.setRowCount(2);
obj.setCellData(data);
obj.setCellFormat(format, 1);
obj.setCellTemplate(new AW.Templates.Combo, 1);
obj.setPopupTemplate(list, 1);
document.write(obj);
(in firebug console)
obj.getCellValue(1,0)
"FR"
obj.getCellText(1,0)
"Germany"
oTempl = oGrid.getHeaderTemplate(4);
oTempl.setStyle('text-align','center');
oTempl.setStyle('font-weight','bold');
var itemText = [], itemLookup = {}, i, items = {'1':'AK','2':'BC','3':'CA','4':'Co. Cork','5':'DF','6':'France','7':'ID','8':'IL','9':'Lancashire','10':'Lara','11':'MT','12':'NM','13':'Nueva Esparta','14':'OR','15':'Québec','16':'RJ','17':'SP','18':'Táchira','19':'WA','20':'WY'};
for (i in items){
itemText.push(items[i]);
itemLookup[items[i]] = i;
}
var cboFormat = new AW.System.Format();
cboFormat.valueToText = function(value){return items[value] || '';};
cboFormat.textToValue = function(text){return itemLookup[text];};
oGrid.setCellFormat(cboFormat, 4, undefined);
var list = new AW.UI.List;
list.setItemText(itemText);
list.setItemCount(itemText.length);
list.focus = function(){};
list.setStyle('color', '#000000');
var cbo = new AW.Templates.Combo;
cbo.setStyle('color', '#000000');
oGrid.setCellTemplate (cbo, 4, undefined);
oGrid.setPopupTemplate(list, 4, undefined);
This topic is archived.