3.2.0

Help in converting 1.0 code to 2.0

Can someone please help!!! me in converting the code below to 2.0?

Code
=================================================
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj = this.prototype;
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});

editor.setAttribute("autocomplete","OFF");
var template;

function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
editor.setEvent("ondblclick", switchToTextMode);
}

obj.setEvent("ondblclick", switchToEditMode);

function switchToTextMode(){
var value = editor.element().value;
var originalText = template.getItemProperty("text");
if(originalText != value) {
var idx = template.grid.getProperty("selection/index");
template.model.setCell(idx,template.column,value);
template.refresh();
template.action("changeInputAction");
}
else {
template.refresh();
}
template = null;
}

editor.setEvent("onblur", switchToTextMode);
editor.setEvent("onkeypress", changeKey);

function changeKey(e){
switch(e.keyCode){
case 27: // esc
editor.element().value=template.getItemProperty("text");
switchToTextMode();
break;
case 13: // enter = down
switchToTextMode();
break;
default:
break;
}
}
};

My.Templates.Input.create();
=====================================================

Then if I have a readonly column I define the column as
var column = new Active.Templates.Text;
obj.setColumnTemplate(column,0);

If it's a readonly column then the column is defined as
var editTemplate = new My.Templates.Input;
editTemplate.model=dataGridData['Gid Name'];
editTemplate.grid=obj;
editTemplate.column=1;
obj.setColumnTemplate(editTemplate,1);

Please let me know how to convert or how to create a template in 2.0 and use that template to define readonly and editable columns.

Thanks!!!
Gary
July 18,
Gary,

cell editing is now available in AW 2.0 by default and does not require special template. You just have to enable editing with setCellEditable() method -

obj.setCellEditable(true); // all cells
  obj.setCellEditable(false, 1); // second column
  obj.setCellEditable(true, 1, 1); // cell-1-1
Alex (ActiveWidgets)
July 19,
Thanks Alex. That took care of my problem.
Gary
July 19,

This topic is archived.

See also:


Back to support forum