Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question about callbacks for TreeGrid.setFields() and Tree.setRoot()

    I am wondering if there is any sort of callback functions that can be used on TreeGrid.setFields() and Tree.setRoot() - I could not find any.

    It seems that these functions are asynchronous and I can not figure out how to detect their completion.

    If I want to do something special right after grid was populated using functions above - for example TreeGrid.getBody() or TreeGrid.autoFitFields() or anything else - how would I achieve that without using setTimeout()?

    The code below demonstrates what I mean: if right after populating grid with TreeGrid.setFields() and Tree.setRoot() I call TreeGrid.getBody() - the body does not exist yet, and TreeGrid.autoFitFields() is ignored, but with setTimeout() - they both work fine.

    Interestingly, in the same scenario calling Tree.openAll() right after populating the grid works as expected.

    Please advice.

    Code:
    isc.TreeGrid.create({
    	ID: "employeeTree",
    
    	data: isc.Tree.create({
    		modelType: "children",
    		nameProperty: "Name",
    		childrenProperty: "directReports"
    	}),
    
    	width: 500,
    	height: 400,
    
    	autoFitWidthApproach:"both"
    });
    
    employeeTree.getData().setRoot({EmployeeId: "1", directReports: [
    	{EmployeeId:"4", Name:"Charles Madigen", directReports: [
    		{EmployeeId:"188", Name:"Rogine Leger"},
    		{EmployeeId:"189", Name:"Gene Porter", directReports: [
    			{EmployeeId:"265", Name:"Olivier Doucet"},
    			{EmployeeId:"264", Name:"Cheryl Pearson"}
    		]}
    	]}
    ]});
    
    employeeTree.setFields([
    	{name: "Name"},
    	{name: "EmployeeId"}
    ]);
    
    if(employeeTree.getBody()){
    	isc.say("Body exists");
    }else{
    	isc.say("Body does not exist")
    }
    
    employeeTree.autoFitFields();
    
    setTimeout(function(){
    	employeeTree.autoFitFields();
    	if(employeeTree.getBody()){
    		isc.say("Body exists");
    	}else{
    		isc.say("Body does not exist")
    	}
    },2000);

    #2
    Running your test case we get "body exists" in both cases. Perhaps you were running it inside the Feature Explorer, which is a specialized environment - run in an actual standalone file to check behavior.

    That said, this is the worst possible way to initialize a component - you are causing it to draw with minimal configuration, then trickling in various information which repeatedly invalidates all the work that's been done so far.

    The best way to initialize a component is to provide all the configuration you can in the call to create(), or at least do so before you call draw().

    Comment


      #3
      Sorry I should have tested more thoroughly - but I adopted our situation to the fallowing example that replicates the issue in stand-alone environment. If I add the grid as an item to a Window, populate it with setFields() and setRoot(), and try to access the grid's body right after that - TreeGrid.getBody() returns null and TreeGrid.autoFitFields() is ignored. In our situation in some cases the grid will be added to a window dynamically and fields and root will also be changed dynamically. We have a need to access body's outer element (TreeGrid.getBody().getOuterElement()) after grid is added to window for some custom functionality.

      Also I need to be able to call autoFitFields() manually after grid is populated since we want the columns to NOT resize in real time - but initializing grid with autoFitWidthApproach: "both" and autoFitFieldWidths: true makes the grid ignore resizeFieldsInRealTime setting (which is set to false) and forces the columns to resize in real time (which is a performance issue for us). When initializing grid - resizeFieldsInRealTime: false only takes effect when autoFitWidthApproach: "value"

      I have already outlined this issue in this post http://forums.smartclient.com/showthread.php?t=31850 but received no response.

      Please try this code and check console to see that right after adding grid as item to window and populating it - the body is null and autoFitFields() is ignored, but after timeout they both are fine.
      Code:
      isc.TreeGrid.create({
      	ID: "employeeTree",
      	data: isc.Tree.create({
      		modelType: "children",
      		nameProperty: "Name",
      		childrenProperty: "directReports"
      	}),
      
      	autoFitWidthApproach:"both"
      });
      
      isc.Window.create({
      	ID: "myWindow",
      	width: 500,
      	height: 400,
      	autoDraw:true
      });
      
      myWindow.addItem(employeeTree);
      
      employeeTree.getData().setRoot({EmployeeId: "1", directReports: [
      	{EmployeeId:"4", Name:"Charles Madigen", directReports: [
      		{EmployeeId:"188", Name:"Rogine Leger"},
      		{EmployeeId:"189", Name:"Gene Porter", directReports: [
      			{EmployeeId:"265", Name:"Olivier Doucet"},
      			{EmployeeId:"264", Name:"Cheryl Pearson"}
      		]}
      	]}
      ]});
      
      employeeTree.setFields([
      	{name: "Name"},
      	{name: "EmployeeId"}
      ]);
      
      console.log("Grid Body:", employeeTree.getBody());
      
      employeeTree.autoFitFields();
      
      setTimeout(function(){
      	console.log("Grid Body:", employeeTree.getBody());
      	employeeTree.autoFitFields();
      },2000);
      Last edited by jumple; 26 Dec 2014, 11:49.

      Comment


        #4
        The TreeGrid just needs to have been draw()n in order for the body to be available. See Layout.reflowNow() (the Window's body, where items are added, is a Layout by default).

        Comment


          #5
          Awesome, thanks a lot, this is exactly what I needed.

          Of course I would rather not call autoFitFields() manually but set it to true in grid's initialization... Is there any way to force columns to not resize in real time with autoFitWidthApproach: "both", autoFitFieldWidths: true, resizeFieldsInRealTime: false?

          Comment


            #6
            Originally posted by jumple View Post
            Of course I would rather not call autoFitFields() manually but set it to true in grid's initialization... Is there any way to force columns to not resize in real time with autoFitWidthApproach: "both", autoFitFieldWidths: true, resizeFieldsInRealTime: false?
            This is now fixed in SmartClient_v100p_2014-12-30_LGPL, thanks for fixing

            Comment

            Working...
            X