Page 1 of 1

DynaTree: Node Level

PostPosted: 07 Jul 2014 13:13
by asp
Hello!

For some tasks it is necessary to know the level of the particular node. Is it possible now? Or, could you add this attribute to the tree node?

Re: DynaTree: Node Level

PostPosted: 07 Jul 2014 15:32
by Alexander Bulei
Hi asp,

Please check the attached demo.

We have published the jsGetActiveNode method and added new tree node command "dtnGetLevel" (check comments in demo) in next build.

Best Regards.

Re: DynaTree: Node Level

PostPosted: 08 Jul 2014 09:01
by asp
Thank you!

I've understood how to deal with the level when you have an active node. But how to get the level in OnGetChildrenNode event handler if I, for example, don't want to load nodes having the level more then 3.

Re: DynaTree: Node Level

PostPosted: 08 Jul 2014 11:46
by Alexander Bulei
Hi asp,

You have two ways to check it:

  • Using the var on server and inc on GetChildrenNodes event.
  • Extend the passed node parameters onLazyRead event:

    delphi code
    procedure TIWForm3.IWAppFormCreate(Sender: TObject);
    begin
    IWCGJQDynaTree1.JQDynaTreeOptions.OnLazyRead.Script:= 'function(dtnode){ dtnode.data.nodeLevel = dtnode.getLevel(); }';
    end;

    procedure TIWForm3.IWCGJQDynaTree1GetChildrenNodes(Sender: TObject; ANodeData: ISuperObject; var AJSon: ISuperObject);
    var
    JSonObj: ISuperObject;
    I: Integer;
    nLvl: Integer;
    begin
    nLvl:= ANodeData.I['nodeLevel'];
    AJSon:= TSuperObject.Create(stArray);
    for I := 1 to 5 do
    begin
    JSonObj:= SO();
    JSonObj.S['key']:= 'childId_' + IntToStr(i);
    JSonObj.S['title']:= 'Child ' + IntToStr(i);
    JSonObj.B['isLazy']:= True; // load children via ajax
    AJSon.AsArray.Add(JSonObj);
    end;
    end;

Best Regards.

Re: DynaTree: Node Level

PostPosted: 09 Jul 2014 10:13
by asp
Thank you!