View Full Version : Enabling checkboxes on TreeNodes at runtime?

30 Oct 2009, 1:00 PM
The nodes in the standard TreePanel can have a checkbox displayed against them. The checkbox appears if the object fetched by the TreeLoader to create the TreeNode had a 'checked' attribute. Once rendered, you can toggle the checkbox with treenode.getUI().toggleCheck().

The problem I have is that the data used to create the node in my case doesn't have a checked attribute (and shouldn't - the checked status is not known by the backend, and the same backend is also used in situations where we don't want a checkbox). toggleCheck() does nothing in this case (as documented).

I can't seem to find a way to enable the display of the checkbox at runtime. I tried adding an 'beforeappend' handler to the TreePanel, but I think it's too late by then, the node has already been created without a checkbox.

I think what I need to do is to intercept the data before the node is created and set the checked attribute. I tried this:

function (t, nodeobj, ajaxresponse) {
var data = Ext.util.JSON.decode(ajaxresponse.responseText);
for (var i = 0; i < data.length; i++) {
data[i].checked = false;
ajaxresponse.responseText = Ext.util.JSON.encode(data);
);But that didn't do the business (quite apart from being filthy).

I suppose I have the option of adding a parameter to the backend URL to cause it to add checked = false onto every node, but that's polluting an otherwise clean API with UI guff.

Is there a nice way to enable the checkboxes at runtime?

30 Oct 2009, 1:04 PM
Ah nadgers, forgot to use the forum search before posting. -50 dkp!

The answer is here:


In summary: use baseAttrs when initialising the TreeLoader.