Checkbox template of my dream ;-)
Checkbox template of my dream ;-)
Following is my attempt to make ideal checkbox template and I made by subclass-ing Active.System.Control so it has got improvements over any earlier suggested solution. The main benefit is - grid is managing checked/unchecked values automatically :-) Tell template that it is âY/Nâ or âYes/Noâ or âTrue/Falseâ or âActive/Inactiveâ or whatever your checked/unchecked values are.
Looking for some feedback â especially from those who appreciate OO programming and cleaner APIs.
JS Code:
CSS Code:
Sample Code:
Cheers,
Sudhaker
Following is my attempt to make ideal checkbox template and I made by subclass-ing Active.System.Control so it has got improvements over any earlier suggested solution. The main benefit is - grid is managing checked/unchecked values automatically :-) Tell template that it is âY/Nâ or âYes/Noâ or âTrue/Falseâ or âActive/Inactiveâ or whatever your checked/unchecked values are.
Looking for some feedback â especially from those who appreciate OO programming and cleaner APIs.
JS Code:
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
// ****************************************************************
// Checkbox Cell Template.
// ****************************************************************
My.Templates.Checkbox = Active.System.Control.subclass();
My.Templates.Checkbox.create = function(){
var obj = this.prototype;
obj.defineModel("checked");
obj.defineCheckedProperty("true", "Y");
obj.defineCheckedProperty("false", "N");
obj.setClass("templates","checkbox");
var checkbox = new Active.HTML.INPUT;
checkbox.setClass("input","checkbox");
checkbox.setClass("checkbox", function(){return this.getColumnProperty("index")});
checkbox.setAttribute("type","checkbox");
checkbox.setAttribute("checked", function(){
return (this.getItemProperty("text") == this.getCheckedProperty("true"))
});
function toggleValue(){
var originalVal = this.getItemProperty("text");
var newValue = (originalVal == this.getCheckedProperty("true")) ? this.getCheckedProperty("false") : this.getCheckedProperty("true");
this.setItemProperty("text", newValue);
this.refresh();
}
checkbox.setEvent("onclick", toggleValue);
obj.setContent("checkbox", checkbox);
};
My.Templates.Checkbox.create();
// ****************************************************************
// CheckboxLabel Cell Template.
// ****************************************************************
My.Templates.CheckboxLabel = My.Templates.Checkbox.subclass();
My.Templates.CheckboxLabel.create = function(){
var obj = this.prototype;
var label = new Active.HTML.SPAN;
label.setClass("checkbox","label");
label.setContent("text", function() { return this.getItemProperty("text"); });
obj.setContent("label", label);
};
My.Templates.CheckboxLabel.create();
CSS Code:
.active-input-checkbox {vertical-align: middle; padding: 0px 5px; margin: -1px 0px 0px;}
.active-checkbox-label {margin-left: 5px;}
Sample Code:
// create checkbox template (or checkbox with label)
// var checkbox = new My.Templates.Checkbox;
var checkbox = new My.Templates.CheckboxLabel;
// set checked/unchecked values
checkbox.setCheckedProperty("true", "Yes")
checkbox.setCheckedProperty("false", "No")
// assign this template to columns 5
obj.setColumnTemplate(checkbox, 5);
Cheers,
Sudhaker
Sudhaker Raj
October 14,