ariacom / Seal-Report

Database Reporting Tool and Tasks (.Net)
https://sealreport.org
Other
1.43k stars 467 forks source link

Series order: Model column Sort option to be taken in count #17

Closed andr3i4o closed 5 years ago

andr3i4o commented 5 years ago

The browser is not order the columns defined in the model in the way they should be. Instead the columns are taken randomly and this probably is not desirable behavior.

ariacom commented 5 years ago

Thank you for your request, it seems relevant and I will integrate it. Can you consider also the changes for Plotly and ChartJS. The sort will not have effect for series created by splitter values (e.g. 1 serie for each product category), so I would enhance this fix by adding .ThenByDescending or Ascending (i => i.SerieDisplayName). Can you check this and finalize the request ?

andr3i4o commented 5 years ago

Hello, thank you for the fast responce and the suggestions. I've updated the other files and added the additional sorting you've proposed. Please take a look.

ariacom commented 5 years ago

Great and thank you, a last remark: ThenByDescending should be either Ascending or Descending if the sort is defined asc or descending on the column... I will see if I have a simple solution or I let you make a suggestion.

ariacom commented 5 years ago

I made the fix and commit it. Finally I implemented an IComnparer that uses FinalSortOrder first then the SplitterValues. Will be part of the next release.

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;
        }
    }