Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Sorting in tree grid(issue with sorting parent and child rows)
Sorting in tree grid [message #1065468] Tue, 25 June 2013 19:58 Go to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Hi,

I am using tree grid and I am seeing an issue with Sorting with child rows. The desired functionality that I expect with Sorting when there are child rows is that it sorts all the parent rows in the ascending or descending order and then for each parent row, sort the child rows inside in the corresponding order. But it currently includes both parent and child rows when sorting is applied and hence the parent and child relationship is not preserved in the sorting. Is there a way to override this functionality such that all parent rows are sorted together and then inside parent row, sort the child rows?
Re: Sorting in tree grid [message #1065478 is a reply to message #1065468] Tue, 25 June 2013 21:15 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I'm pretty sure the way you describe the desired functionality works easily. As I'm not sitting in front of the code right now, I can't point to the correct position. But I think there should be special comparator needed in one of the tree related classes.
Re: Sorting in tree grid [message #1065578 is a reply to message #1065478] Wed, 26 June 2013 14:46 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
I still couldn't figure out which compartor to use to achieve the desired behavior. When you get a chance to see the code,please let me know which comparator would help acheive this.
Re: Sorting in tree grid [message #1065580 is a reply to message #1065578] Wed, 26 June 2013 14:56 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Did you have a look at the TreeGridExample and the SortableTreeComparator that uses the GlazedLists.beanPropertyComparator in the TreeList.Format class?
Re: Sorting in tree grid [message #1065600 is a reply to message #1065580] Wed, 26 June 2013 15:41 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Yes. In the SortableTreeComparator for the beanPropertyComparator I have to pass a property name which I believe is for peforming sorting based on the property? But I would need to peform sorting on different columns and hence I used the Lables and added compartors using configregistry. Can that also be achieved through SortableTreeComparator or what the property name that we pass to beanPropertyComparator used for?

Also I am using IColumnPropertyAccessor to provide data for different columns and they do not come from different properties of an object. Here is my property accessor code

/*
	 * Class that provides the grid column values
	 */
	private class ColumnPropertyAccessor implements IColumnPropertyAccessor<DataRow>
	{

		@Override
		public int getColumnCount()
		{
			return NumCols;
		}

		@Override
		public Object getDataValue( DataRow row, int col )
		{
			//System.out.println("col accessor for Row: " + row.getAddress() + "Col: " + col );
			String value;
			if( col == 0 )
				value = row.getName();
			else
				value = row.getData( col - FirstValueCol );
			return value;
		}

		@Override
		public void setDataValue( DataRow row, int col, Object newValue )
		{
			if( col >= FirstValueCol )
				row.setData(  col - FirstValueCol, (String)newValue );
		}

		@Override
		public int getColumnIndex( String arg0 )
		{
			return 0;
		}

		@Override
		public String getColumnProperty( int arg0 )
		{
			return null;
		}

	}

Re: Sorting in tree grid [message #1065602 is a reply to message #1065600] Wed, 26 June 2013 15:45 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I think the problem is that you are trying to sort the tree column. And in your tree column you have different values. At least this is my understanding of your issue.

As you need to implement the TreeList.Format class per project, maybe you just need to implement a custom comparator that fits your needs internally and use this instead of the GlazedLists.beanPropertyComparator.
Re: Sorting in tree grid [message #1065604 is a reply to message #1065602] Wed, 26 June 2013 16:02 Go to previous messageGo to next message
Testr t is currently offline Testr tFriend
Messages: 93
Registered: April 2013
Member
Okay. I am performing sorting on the tree column(say Name) and another column(say Age) and they all come from same object(say DataRow). When I use SortableTreeComparator it now works correctly by performing parent rows first and then the child rows inside it. But I do not understand why we have to pass a propertyName(I passed in "age") for the GlazedLists.beanPropertyComparator. Is it for default sorting when the grid opens up?

As I had the comparators for different columns(Default and NullComparator) its using them correctly. For my better understanding, does Nattable combine both the SortableTreeComparator and the comparators for different columns?
Re: Sorting in tree grid [message #1065703 is a reply to message #1065604] Thu, 27 June 2013 08:20 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
But I do not understand why we have to pass a propertyName(I passed in "age") for the GlazedLists.beanPropertyComparator. Is it for default sorting when the grid opens up?


The GlazedLists.beanPropertyComparator is from GlazedLists. It compares based on the specified property name. The first parameter, in this case the GlazedLists.beanPropertyComparator, is the main comparator to sort the first level (you name it root) in the tree. In case the values are different, the column comparators will get active.

Quote:
does Nattable combine both the SortableTreeComparator and the comparators for different columns?


Well technically the SortableTreeComparator makes use of the comparators that can be retrieved via SortModel. The SortableTreeComparator is the one who does it, not the NatTable.

Sometimes it helps reading the source code!
Previous Topic:Display values in GroupBy tree nodes
Next Topic:Selection not working with disabled sorting
Goto Forum:
  


Current Time: Fri Apr 19 06:56:01 GMT 2024

Powered by FUDForum. Page generated in 0.02306 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top