Is it possible to have a different order in groups than in subordinate rows?

Posted by: jordi.rierababures on 18 July 2018, 8:23 pm EST

    • Post Options:
    • Link

    Posted 18 July 2018, 8:23 pm EST

    We are working with FlexGrid (Angular 4+) with two group levels. By default, sorting by a column implies sorting the groups also by the same column.

    But we would like to sort the groups using a given column (fixed), but also we want to allow sorting the subordinate rows using any wijmo columns available (selected by the user).

    That is, the group sorting should be fixed, while the inside rows for each group should be ordered as the user likes it.

    Is this scenario possible? Any help in the right direction would be appreciated.

  • Posted 19 July 2018, 11:20 pm EST

    Hi,

    You can achieve the desired functionality by handling the sortingColumn event and define the sortDescriptions manually.

    Please refer to the following sample which implements the above requirement:-

    http://jsfiddle.net/mkgupta911/gkc5j6rL/4/

    For a similar solution in angular, you may refer to the sample:-

    https://stackblitz.com/edit/angular-wsghat?file=app%2Fapp.component.ts

    ~Manish

  • Posted 22 July 2018, 9:19 pm EST

    Hi Manish,

    Thanks for your answer. Now I can have the groups “fixed” while sorting the normal row elements by whatever column is being clicked.

    But… I would like to sort the groups (headers) by using its aggregate property value, let’s say its “Total” column. I’ve tried to use sortConverter, but it seems that only the “raw” data items are going through it. So, if I return item.Total for sorting the groups, all the table is sorted by that column, and not only the groups.

    I hope I made my problem clear enough…

  • Posted 23 July 2018, 11:47 pm EST

    Hi,

    If we understand correctly then you would like to sort the grid also via the groups with respect to their aggregate value.

    If that is the case then you may refer to the following sample which uses sort converter to implement the given requirement:-

    https://stackblitz.com/edit/angular-11hbxb?file=app%2Fapp.component.ts

    In the sample above try to sort the downloads column, it will sort the downloads sub group within country group according to the aggregate value.

    If you were looking for something else then please feel free to explain more about your requirement.

    Regards

  • Posted 24 July 2018, 9:05 pm EST

    Hi Manish,

    Perfect and to the point, as always !

    The only thing is that the sortConverter method is called each time the item is involved in the sort process (i.e. when exchanging two items positions). So, the calculus is repeated multiple times for each item. When using large tables, when performance could be an issue, it could be best to use some kind of hash.

    Regards

  • Posted 26 July 2018, 5:27 am EST

    Hi,

    We are glad to hear that we were able to help.

    Thanks for your valuable feedback.

    Maintaining hash of values is a great idea but it might not be the best solution in the dynamic nature of grid. Suppose the data is changed after the hash is created then it might not map all the possible values, one may argue that we can sync the hash after edits are made simple by means of cellEditEnded but then again the developer might be editing some values in the source in such a case developer would have to explicitly inform the grid about the change thus adding an extra layer of complexity, also it would decrease the edit performance as for each edit new hash value for cell needs to be calculated and updated.

    The real problem comes when the converter function is not a pure function or is depending on some state to convert sort values i.e. referring to some value outside the function scope then hash may not always represent the correct converted values.

    Hope it clears!!!

    ~Manish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels