Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by C. Bernstein on Jul 02, 2009 04:24
open dhtmlx forum
onClick event when expanding a node in the tree grid

Is there an onClick event when clicking a plus sign to expand a node in the tree grid (using dynamic loading)? On a similar note, where can I find documentation on all of the onClick events for the grid/tree grid?

Thanks.
Answer posted by dhxSupport on Jul 02, 2009 05:31
You can use "onOpenStart" and "onOpenEnd" events. Please find more information about availible events here http://dhtmlx.com/docs/products/dhtmlxGrid/doc/events.html#grid_api_ev
Answer posted on Jul 02, 2009 07:14
I am using the onOpenStart() event but it is not giving me what I need.  I am trying to retrieve the number of rows in the grid after the node has been expanded.  When I print out the number of rows in the grid (gird.onRowsNum()) in the event, it's the number of rows before the node got expanded.  Also, once I attached the event the node does not expand anymore?
Answer posted on Jul 02, 2009 08:53
>>it's the number of rows before the node got expanded
Yes, onOpenStart event occurs when opening initiated, but not started yet. You should use "onOpenEnd" event instead
>>Also, once I attached the event the node does not expand anymore
This event is blockable. If event returns: true - confirms opening/closing; false - denies opening/closing. So your code should looks like that:
grid.attachEvent("onOpenStart", function(id,state){
//your code here
return true;
});

Answer posted on Jul 02, 2009 08:58

Using the onOpenEnd event doesn't work for me because that only gets fired when the node is being closed.  I need an event that fires after the node has been expanded but before it is closed.  How can I do this?

Thank you.

Answer posted on Jul 02, 2009 09:24
onOpenEnd event occurs when branch opened (in case of dyn. loading - after xml loading). This event passes the following parameters:
id - id of the node that will be opened/closed;
state - current open state of tree item; -1 means that the item is closed, 1 - item is opened.

So to detect if branch was opend and all row was loaded you should use:
 grid.attachEvent("onOpenEnd", function(id,state){
 if (state) {
//items is opend
}
if (!state) {
//items is closed
}
});
Answer posted on Jul 02, 2009 09:34
When I attach the onOpenEnd event, it fires only when I try to collapse the expanded node, not when the node is expanded???
Answer posted by dhxSupport on Jul 06, 2009 01:13
Could you please provide us any kind of sample where we can reproduce this issue? (You can send such example directly to the support@dhtmlx.com)
Answer posted on Jul 06, 2009 05:16

The following is the code for onOpenEnd().  Does it look correct?

this.attachEvent("onOpenEnd",function(id){
  this._redrawLines(id)
 });

Answer posted by dhxSupport on Jul 06, 2009 06:05
This code is correct. "this" should be reference to the dhmlxGrid object.