yd290276
11 Dec 2010, 3:20 AM
Hi all,
i think tree grid is wonderfull component, but i need to add check box support in column. So the treegrid component doesn't provide such functionnality.
Therefore, i add a quick and dirty patch to provide the tree grid habilty to display checkboxes in columns. See aboce how i accomplish this.
1) set a "tpl" property for the column you want to display checkbox and add a "dataIndex" property, for example in my column 'is_auth'
tpl : function(a) {
var html = '';
var isBool = Ext.isBoolean(this.is_auth);
if (isBool && this.type == 'privilege') {
html = ['<input dataIndex="is_auth" class="x-tree-node-cb" type="checkbox"',
(this.is_auth == true) ? 'checked="checked"' : '', '/>'];
} else {
html = [];
}
html = html.join('');
return html;
}
2) Use my uiProvider for node :
/**
* Overrides event onCheckChange to handle checkbox status changing in column
* tree grid
*/
Ext.ns('Ext.ux.tree');
ux.tree.booleanTreenodeUI = Ext.extend(Ext.ux.tree.TreeGridNodeUI, {
/**
* get check box status from html input checkbox element and get
* property "dataIndex" from html element to update column value
*
* @param {}
* e
*/
onCheckChange : function(e) {
var dataIndex = e.target.getAttribute('dataIndex');
if (dataIndex) {
var checked = e.target.checked;
this.node.attributes[dataIndex] = checked;
this.fireEvent('checkchange', this.node, checked);
} else {
var err = new Ext.Error('[dataIndex] property not found');
throw err;
}
},
/**
* override toggleCheck : do nothing because we can't know wich
* column is to be updated
*
* @param {}
* value
*/
toggleCheck : function(value) {
return;
}
});
so this way, it is possible to add a checkbox in any column you want and it handles event "onCheckChange". Notice that method "toggleCheck" is unactive since it is impossible to toggle check box as node can contains many checkboxes.
Hope it can help and wait for comments !
Thank you.
i think tree grid is wonderfull component, but i need to add check box support in column. So the treegrid component doesn't provide such functionnality.
Therefore, i add a quick and dirty patch to provide the tree grid habilty to display checkboxes in columns. See aboce how i accomplish this.
1) set a "tpl" property for the column you want to display checkbox and add a "dataIndex" property, for example in my column 'is_auth'
tpl : function(a) {
var html = '';
var isBool = Ext.isBoolean(this.is_auth);
if (isBool && this.type == 'privilege') {
html = ['<input dataIndex="is_auth" class="x-tree-node-cb" type="checkbox"',
(this.is_auth == true) ? 'checked="checked"' : '', '/>'];
} else {
html = [];
}
html = html.join('');
return html;
}
2) Use my uiProvider for node :
/**
* Overrides event onCheckChange to handle checkbox status changing in column
* tree grid
*/
Ext.ns('Ext.ux.tree');
ux.tree.booleanTreenodeUI = Ext.extend(Ext.ux.tree.TreeGridNodeUI, {
/**
* get check box status from html input checkbox element and get
* property "dataIndex" from html element to update column value
*
* @param {}
* e
*/
onCheckChange : function(e) {
var dataIndex = e.target.getAttribute('dataIndex');
if (dataIndex) {
var checked = e.target.checked;
this.node.attributes[dataIndex] = checked;
this.fireEvent('checkchange', this.node, checked);
} else {
var err = new Ext.Error('[dataIndex] property not found');
throw err;
}
},
/**
* override toggleCheck : do nothing because we can't know wich
* column is to be updated
*
* @param {}
* value
*/
toggleCheck : function(value) {
return;
}
});
so this way, it is possible to add a checkbox in any column you want and it handles event "onCheckChange". Notice that method "toggleCheck" is unactive since it is impossible to toggle check box as node can contains many checkboxes.
Hope it can help and wait for comments !
Thank you.