:: Forum >>
Editable Grid Saving issue
I am using an editable grid and trying to save the resulting data to an xml file. I have attempted to use the following code based on examples with setting up a data model template. However, I keep getting an error on this line:
obj.setDataModel(table);
stating the method is not supported on AW.UI.Grid...is there a workaround for this object? Code below:
<script type="text/javascript" language="javascript">
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Input = AW.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj1 = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new AW.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj1.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var value = editor.element().value;
template.setItemProperty("text", value);
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Input.create();
var temp = new My.Templates.Input;
var table = new AW.XML.Table;
table.setURL("Files/tableView.xml");
table.request();
var columns = ["ID", "User Story", "Component", "Task Name", "Skillset", "Estimate (iDays)"];
var obj = new AW.UI.Grid;
obj.setId("myGrid");
obj.setColumnCount(6);
obj.setHeaderText(columns);
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
obj.setCellFormat([str, str, str, str, str, num]);
obj.setCellModel(table);
table.setText = function(value, i, j){
var node = this.getNode(i, j);
node.text = value;
}
// write grid html to the page
obj.setCellEditable(true);
obj.setCellEditable(false, 0);
// assign new template to all columns
obj.setColumnTemplate(temp);
// provide external model as a grid data source
obj.setDataModel(table);
document.write(obj);
document.write("<br>");
var label = new AW.UI.Label;
document.write(label);
Jeff Karp
Wednesday, December 12, 2007
Figured it out. Code below for an editable grid
<script type="text/javascript" language="javascript">
var table = new AW.XML.Table;
//Need to append date+milleseconds so the grid refreshes
var d = new Date();
table.setURL("Files/Table/tableView.xml?"+d.getDate()+d.getMilliseconds());
table.request();
var columns = ["ID", "User Story", "Component", "Task Name", "Skillset", "Estimate (iDays)"];
var obj = new AW.Grid.Extended();
obj.setId("myGrid");
obj.setColumnCount(6);
obj.setHeaderText(columns);
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
obj.setCellFormat([str, str, str, str, str, num]);
obj.setCellModel(table);
table.setText = function(value, i, j){
var node = this.getNode(i, j);
node.text = value;
}
// write grid html to the page
obj.setCellEditable(true);
obj.setCellEditable(false, 0);
obj.setCellEditable(false, 1);
obj.setCellEditable(false, 2);
obj.refresh();
document.write(obj);
document.write("<br>");
</script>
Jeff Karp
Thursday, December 13, 2007
This topic is archived.
Back to support forum
Forum search