Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Marc  
#1 Posted : Thursday, March 21, 2013 10:43:08 AM(UTC)
Marc

Rank: Member

Groups: Registered
Joined: 5/9/2012(UTC)
Posts: 15
Man
Location: Bern

Hi Igor, hi everybody,

I have a grid containing hierarchical structures, e.g. a contact list like shown below:

Code:

Column "NAME"             Column "REVENUE"

Company A                 140
   |__ Department 1        90
         |__ Person NN     60
         |__ Person LL     30
   |__ Department 2        50
         |__ Person XY     50
Company B                 200


If I use the sort function on column "REVENUE", iGrid switches positions of persons "NN" and "LL".
Everthing fine so far.

Sometimes it would be nice to:
a) switch between a hierarchical (tree) view and a flat view of the same data
b) have the grid ordered by "REVENUE" without considering the persons' parent/child relationship.

Is there an easy way to switch between a tree view and a flat view without rebuilding the grid (i.e. reload data without parent/child relationship)?
If yes, is it possibly to apply the sort function to the whole set of data without considering existing parent/child relationship?

Expected result:
Code:

Column "NAME"             Column "REVENUE"

Person LL                  30
Department 2               50
Person XY                  50
Person NN                  60
Department 1               90
Company A                 140
Company B                 200


I have tried to set TreeCol="some hidden column" which works fine to display the "NAME" column flat. But of course, this does not affect the sort behaviour.

Thank you for shareing your thoughts on that question!

Kind regards,
Marc

Edited by moderator Tuesday, June 30, 2015 3:56:20 PM(UTC)  | Reason: Edited by Igor/10Tec: formatted grid data sample with monospace font

Igor/10Tec  
#2 Posted : Friday, March 22, 2013 9:43:10 AM(UTC)
Igor/10Tec

Rank: Administration

Groups: Administrators, Forum Moderator
Joined: 1/17/2011(UTC)
Posts: 1,111

Thanks: 15 times
Was thanked: 141 time(s) in 141 post(s)
It's a very good question - appreciate it. I'm gonna even to move it to the KB section.

When iGrid has a tree and hierarchical data (non-zero RowLevel's), it sorts its data using the node relationships automatically. That's normal behavior. To convert it to flat view, you just need to remove the info about hierarchy - just reset the RowLevel/RowTreeButton properties.

But if you wish to SWITCH between tree and flat view, you need to store the original relationships somewhere. Below is an example of such a sub in which I imply we use the special hidden 4th, 5th and 6th columns to store the original tree structure:

Code:
Private Sub FlatView()
   With iGrid1
      .BeginUpdate
      
      .TreeCol = 0
      
      Dim iRow As Long
      For iRow = 1 To .RowCount
         .CellValue(iRow, 4) = .RowLevel(iRow)
         .RowLevel(iRow) = 0
         .CellValue(iRow, 5) = .RowTreeButton(iRow)
         .RowTreeButton(iRow) = igRowTreeButtonAbsent
         .CellValue(iRow, 6) = iRow
      Next
      
      .EndUpdate
   End With
End Sub


To restore the original tree look, use a sub like the following:

Code:
Private Sub TreeView()
   With iGrid1
      .BeginUpdate
      
      .TreeCol = 1
      
      .SortObject.Clear
      .SortObject.AddItem 6
      .Sort
      
      Dim iRow As Long
      For iRow = 1 To .RowCount
         .RowLevel(iRow) = .CellValue(iRow, 4)
         .RowTreeButton(iRow) = .CellValue(iRow, 5)
      Next
      
      .EndUpdate
   End With
End Sub


Pay attention to the fact that we store the original row order. If we do not do that and simply restore RowLevel/RowTreeButton, it's not right in the general case as the tree structure (node order) may be already corrupted after sorting in flat view.

Have I missed something?
Marc  
#3 Posted : Friday, March 22, 2013 5:06:44 PM(UTC)
Marc

Rank: Member

Groups: Registered
Joined: 5/9/2012(UTC)
Posts: 15
Man
Location: Bern

Thanks a lot. That is exactly what I am looking for!

Regards,
Marc
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.