Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
Custom comparer
Hi,
does OI/ SRP have a sort function that you can pass a custom compare function to? My compare logic is quite complicated, and while I can achieve my compare using multiple columns , the code is quite hard to read. Having a custom comparer would be much more maintainable.
does OI/ SRP have a sort function that you can pass a custom compare function to? My compare logic is quite complicated, and while I can achieve my compare using multiple columns , the code is quite hard to read. Having a custom comparer would be much more maintainable.
Comments
Basically, I am trying to sort the itemList array of the SRP tree control so that it has the order I want.
1. I need case insenstive sort.
2. I need siblings to be next to each other, and the first sibling to be after its parent.
3. I need the parents to be sorted in a particular order (based off a number that each parent is assigned)
I can achieve this by appending a bunch of columns to each item in the itemList which contain data that allow me to sort the rows correctly, but i'd rather not do this, as the code is quite hard to read.
I was just wondering if there was a function i could define that determined which of two items was the bigger/smaller.
Honestly, I do this myself to make sorting the way I want easier. I then use the Rotate service so my "sort" columns are easy to remove using the Delete function and then I Rotate back.
Bigger/smaller in what way? I'm assuming you don't mean in string length, since you could use the Len function for that.
thanks
another suggestion though. It would be cool if the sort didn't just sort by the data column of the item.
In my project, I have items that have names:
Shop by Brand
Shop by Category
Shop Clearance
but the order that they should be displayed in is not based off the names. It's based of a number that each item has (which i don't want to display).
So it would be useful if you added a new column to the items of the itemList which allowed you to specify the order in which the items should be sorted.
"Bigger/smaller in what way? I'm assuming you don't mean in string length, since you could use the Len function for that."
That's my point, the criteria that determine which item is greater could be anything. In my case, i have 2 kinds of items that can appear in my tree: groups and hierarchies. This is the sort criteria:
2. Hierarchies should be sorted case insensitively
3. Groups should be sorted according to a number that each is assigned
4. Hierarchies which are sibling should appear next to each other, but the first sibling should appear immediately after a particular group.
I can achieve this by appending a bunch of columns, but i'd rather have one function where I can define these rules, as they are complex.
But it's no big deal. Since you do the column thing as well, i'm sure it will be fine.
This is what I am talking about:
The shop by nodes are groups, and the thing with numbers at the end of them are hierarchies
I personally disagree with your UI design here. By placing group names before their numbers, the eye is attracted to the names. Thus, sorting by numbers here is counter-intuitive. It seems to me that if numbers are more important, you should place them first, affording the user to expect sorting by numbers. Once you do this, the table will be able to sort by numbers just fine (assuming each number has the same number of digits). Moreover, since you have a search field, names really are ancillary. If the user already knows the name, it's more efficient to just search anyway.
Food for thought.
oh you have misunderstood. Let me explain again.
The things in the second orange box are "real" nodes. They are to be sorted in alphabetical order by their names. The things in the first orange box are "fake" nodes, things that don't actually exist in our data but are simply there to group the real nodes. So I am grouping all of the real nodes that are Gemstones underneath that Shop by Gemstone node. Similarly, all of the real nodes that are brands will appear under the Shop by Brand node.
It is those fake "Shop by" nodes that are to be sorted by a number called the Display order. In the screenshot above, the Shop by Brand has a display order of 1 (of course, you can't see this number as it is metadata about the node), thus it will appear at the top, and the Shop by Gemstone has a display order of 2, thus it will appear underneath all other fake "shop by" nodes with a display order of 1. So as you can see, I am needing to sort these fake nodes by an attribute that I don't want to display to the user.
But as I said, don't worry about implementing all of this, as i have gotten it to do everything I want by calling your sort function rather than relying on the tree to sort everything for me.
Btw, this is what we are trying to represent:
https://www.itvsn.com.au/
go to the department section