logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


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

Notification

Icon
Error

Options
Go to last post Go to first unread
netpacket  
#1 Posted : Monday, July 22, 2019 10:07:13 AM(UTC)
netpacket

Rank: Advanced Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 33
Man
Switzerland

Thanks: 13 times
Hi
I have a report model with splitter. The splitter is a 4 or 5 digits number.
As long as I have 5 digits or 4 digits numbers alone , the sort is perfect as you can see in the image below:
5D

But if I have 4 digits and 5 digits numbers together, sorting doesn't work properly, like this:
4&5D

How can i solve this?
Thanks

Edited by user Monday, July 22, 2019 10:09:40 AM(UTC)  | Reason: Not specified

epf  
#2 Posted : Tuesday, July 23, 2019 6:46:03 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
! This POST is out of date, CHECK UPDATE AT THE LAST POST !

The sort of the series is done in the related Chart Template at the line:
Code:

@foreach (ResultSerie serie in page.Series.Where(i => i.Element.Nvd3Serie != NVD3SerieDefinition.None).OrderBy(i => i, new ResultSerieComparer()))



The current ResultSerieComparer implementation sort first by splitter element order, then by splitter value converter in string (as several element can be a splitter, the splitter value can have several element values separated by commas).
Here is the current implementation:
Code:
    public class ResultSerieComparer : IComparer<ResultSerie>
    {
        int IComparer<ResultSerie>.Compare(ResultSerie x, ResultSerie y)
        {
            ResultSerie sx = x as ResultSerie;
            ResultSerie sy = y as ResultSerie;

            //Priority to element sort order
            if (sx.Element != sy.Element) return string.Compare(sx.Element.FinalSortOrder, sy.Element.FinalSortOrder);
            else
            {
                //Then by splitter values descending or ascending
                var result = string.Compare(sx.SplitterValues, sy.SplitterValues);
                if (sx.SplitterCells.Length > 0 && sx.SplitterCells[0].Element != null && !sx.SplitterCells[0].Element.SortOrder.Contains(SortOrderConverter.kAscendantSortKeyword))
                {
                    return -1 * result;
                }
                return result;
            }
        }
    }




In your case, the splitter is a numeric value, so you should change the ResultSerieComparer implementation:
just create a new class in your template to do the job:
Code:
@functions {
    public class ResultSerieComparer2 : IComparer<ResultSerie>
    {
        int IComparer<ResultSerie>.Compare(ResultSerie x, ResultSerie y)
        {
            ResultSerie sx = x as ResultSerie;
            ResultSerie sy = y as ResultSerie;

            //Priority to element sort order
            if (sx.Element != sy.Element) return string.Compare(sx.Element.FinalSortOrder, sy.Element.FinalSortOrder);
            else
            {
                //Then by splitter values descending or ascending
                if (double.Parse(sx.SplitterValues) == double.Parse(sy.SplitterValues)) return 0;
                var result = double.Parse(x.SplitterValues) <= double.Parse(sy.SplitterValues) ? -1 : 1;
                if (sx.SplitterCells.Length > 0 && sx.SplitterCells[0].Element != null && !sx.SplitterCells[0].Element.SortOrder.Contains(SortOrderConverter.kAscendantSortKeyword))
                {
                    return -1 * result;
                }
                return result;
            }
        }
    }
}



Then replace ResultSerieComparer by ResultSerieComparer2, it should work

PS: in attachment is my sample based on Northwind
Custom Series Sort2.srex (26kb) downloaded 3 time(s).

Edited by user Thursday, November 12, 2020 4:41:21 PM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
netpacket on 7/23/2019(UTC)
netpacket  
#3 Posted : Tuesday, July 23, 2019 9:47:51 AM(UTC)
netpacket

Rank: Advanced Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 33
Man
Switzerland

Thanks: 13 times
Hi epf,
Thanks for you quick reply.
I've executed your attached report and its stuck at rendering report.
epf  
#4 Posted : Tuesday, July 23, 2019 10:06:18 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
Sorry, I forgot to handle the ==, I updated the original post with a new attachment...please check
thanks 1 user thanked epf for this useful post.
netpacket on 8/22/2019(UTC)
netpacket  
#5 Posted : Thursday, August 22, 2019 5:08:22 AM(UTC)
netpacket

Rank: Advanced Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 33
Man
Switzerland

Thanks: 13 times
Works fine now.
The only problem is that whenever I add a chart template to my report , the rendering time is increased about 10 seconds. Suppose if I have 10 charts in the report with templates , then the rendering time will over a minute. Any solution for that?
epf  
#6 Posted : Thursday, August 22, 2019 2:35:57 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
it is strange that the rendering takes so long...using custom template requires to compile it, but it should be done only the first time so the impact should not be so long...
you should try to understand what takes so long
epf  
#7 Posted : Thursday, November 12, 2020 4:38:35 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
UPDATE
From the 6.0, the default implementation has moved to:
Code:
        int IComparer<ResultSerie>.Compare(ResultSerie x, ResultSerie y)
        {
            ResultSerie sx = x;
            ResultSerie sy = y;

            //Priority to element sort order
            if (sx.Element != sy.Element)
            {
                if (sx.Element.FinalSort > sy.Element.FinalSort) return 1;
                else if (sx.Element.FinalSort < sy.Element.FinalSort) return -1;
                return 0;
            }
            else
            {
                //Then by splitter values descending or ascending
                return ResultCell.CompareCells(sx.SplitterCells, sy.SplitterCells);
            }
        }


which will sort the splitter values using the default comparer used for the table, so it will work fine for numeric, datetime, custom sort for an enum, etc.
You may use it if you are below 6.0...

Edited by user Thursday, November 12, 2020 4:39:57 PM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
netpacket on 11/21/2020(UTC)
Users browsing this topic
Guest
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.