Jump to content
  • sorting and grouping on variable


    hvm
    Assigned User teodord
    CategoryFeature request
    PriorityNormal
    ReproducibilityN/A
    ResolutionFixed
    SeverityMajor
    StatusClosed

    We have a report where grouping based on a variable is needed. Grouping on a variable is no problem.

     

    But to let grouping work correctly, the data has to be sorted in the correct order.

     

    At this moment there is no way to sort the data on a report variable.



    User Feedback

    Recommended Comments

    Hi,

     

    We are now considering making this enhancement.

     

    However, I want us to be clear on what we are going to achieve.

    When using sort fields or sort variables, it is understood that the sorting will occur in-memory, after the reporting engine makes a first pass thought the data.

     

    The most obvious drawback of using report fields and report variables for sorting is that the whole report data will end up being cached in memory.

     

    Also, when sorting on a report variable, it does not make much sense for this variable to have a calculation type. For example, it does not make sense to sort on a variable that performs a Sum at some group level. That variable would have an incremented value and sorting on its values would have unexpected results, depending on what other sort criteria the report has.

     

    In some cases, the sort order is not know at report design time. This something we want to solve too.

    So we need a way to pass sort field or sort variable names at runtime, to either completely define the sort order, or add to pre-existing sort criteria with the report.

     

    If you have any suggestions, please comment back on this.

     

    Thanks,

    Teodor

    Link to comment
    Share on other sites

    Hi,

    We understand that sorting will occur in-memory. In our case, the datasets are not that big.

     

    Also, we don’t need a calculation type. The sort-variable can be calculated with a expression based on some of the fields.

     

    About your last question (pass sort field/variable at runtime), it’s difficult for us to give you any suggestions. We don’t have much experience with jasper.

    Hanno

    Link to comment
    Share on other sites

    Hi,

     

    This enhancement was implemented and committed to SVN.

    It will be part of the 3.7.5 release.

     

    It is about the possibility to specify variable names as sortField tags.

    In order to do so the sort field type 'Variable' must be specified as follows:

     

     

    Also, a new build-in parameter called SORT_FIELDS, which expects a List of JRSortField instances as values, can be used to add to the list of dataset sort fields in a dynamic way.

     

    I hope this helps.

    Teodor

    Link to comment
    Share on other sites

    Hi,

     

    I'm new to iReport and have some challenge on sorting based on Variable ahead.

     

    I working with Groups and managed to order and group my data. I put all needed user data nad Variables on Group header band. As I have some calculations on a indiviadual row level(for user), which are then groupped by this user accross the date range I arrived to ok Table showing users and the result of calc made as Variable. This Variable is Integer or Float Type.

     

    Now I came to challenge on sorting. By using new feature as you described above I managed to sort ok by user or even by a Variable type string like username+usersurname. So far ok. But when I want to sort this way by anotehr Variable doing Sum on a Group level then such sorting is working but distracting Grouping a such. So I'm getting all user records sorted by this Variable but all time dates not Grouped.

     

    Is that possible?

     

    Pls advise.

    Thx

    Zbig

    Link to comment
    Share on other sites

    Hi,

     

    I don't fully understand what you are trying to do, but what I can tell you is that sorting on Sum variables does not make sense to JR, because the engine does not pass through your data more than twice.

     

    So it would only make sense to sort on simple variables such as username+surname (calculation=Nothing). The engine goes through your data once, to calculate these simple variables and then sorts them and then the report is filled.

     

    If you have sorted on a Group variable, you have to understand that groups are very strongly related to sorting. If your data is not sorted by the same criteria you have declared your groups, then you end up with a mess.

     

    For example, if you group Orders by Country, you have to make sure your data is sorted by Country, either by an ORDER BY clause in your query or by a , because otherwise you end up with France all over the place. This is because when you declare your group, it does not mean JR will sort your data by that group. Sorting is always your responsibility and you make to make sure your sorting matches your grouping. When you sorted by Sum variables, you ruined your groups.

     

    You have to reconsider your report or explain better what you need to achieve. I suggest you use the forums for that.

     

    Thanks,

    Teodor

    Link to comment
    Share on other sites


×
×
  • Create New...