how to make a cell uneditable dynamically
Hi, how to make a cell uneditable dynamically
sai
June 22,
obj.getRowTemplate(rowIndex).getItemTemplate(itemIndex).setAttribute("readOnly","true")
<html>
<head>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<link href="lib/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="lib/grid.js"></script>
<style>
.active-controls-grid {height: 100%; font: menu;}
</style>
<script>
var myData = [
["MSFT","Microsoft Corporation", "314,571.156", "32,187.000", "55000"],
["ORCL", "Oracle Corporation", "62,615.266", "9,519.000", "40650"],
["SAP", "SAP AG (ADR)", "40,986.328", "8,296.420", "28961"],
["CA", "Computer Associates Inter", "15,606.335", "3,164.000", "16000"],
["ERTS", "Electronic Arts Inc.", "14,490.895", "2,503.727", "4000"],
["SFTBF", "Softbank Corp. (ADR)", "14,485.840", ".000", "6865"],
["VRTS", "Veritas Software Corp.", "14,444.272", "1,578.658", "5647"],
["SYMC", "Symantec Corporation", "9,932.483", "1,482.029", "4300"],
["MSFT","Microsoft Corporation", "314,571.156", "32,187.000", "55000"],
["ORCL", "Oracle Corporation", "62,615.266", "9,519.000", "40650"]
];
var myColumns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];
</script>
</head>
<body>
<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
// *************************************************
// Input Cell Template.
// ***************************************************
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function(){
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.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;
//////////////////////////////////////////
this.action("AskForEdition");
if (editable == "no"){ template = null; }
////////////////////////////////////////
else{
template.element().className += " active-edit-mode ";
template.element().innerHTML = editor;
editor.element().focus();
editor.setEvent("ondblclick", editor.element().focus());
}
}
obj.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 obj = new Active.Controls.Grid;
obj.setRowProperty("count", 10);
obj.setColumnProperty("count", 5);
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setDataText = function(value, i, j){myData[i][j]=value}
obj.setColumnProperty("text", function(i){return myColumns[i]});
var editable = "";
obj.setAction("AskForEdition", function(src){
if (src.getRowProperty("index") > 4 ){editable = "no"};
else {editable = "yes"}
});
var myvar0 = new My.Templates.Input;
var myvar1 = new My.Templates.Input;
var myvar2 = new My.Templates.Input;
var myvar3 = new My.Templates.Input;
var myvar4 = new My.Templates.Input;
obj.setColumnTemplate(myvar0, 0);
obj.setColumnTemplate(myvar1, 1);
obj.setColumnTemplate(myvar2, 2);
obj.setColumnTemplate(myvar3, 3);
obj.setColumnTemplate(myvar4, 4);
document.write(obj);
</script>
</body>
</html>
This topic is archived.
ActiveWidgets is a javascript library for creating user interfaces. It offers excellent performance for complex screens while staying simple, compact and easy to learn. Deployed by thousands of commercial customers in more than 70 countries worldwide.
Copyright © ActiveWidgets 2021