FlexGrid sorting issue

Posted by: eberg on 14 September 2017, 4:29 am EST

  • Posted 14 September 2017, 4:29 am EST

    Our situation:
    We are using a grid with multiple columns and grouping. We want to be able to sort the grid on all levels.
    We made a custom function using a "sortingColumn" handler.


    //some irrelevant hierarchical sort logic left behind

    sorted.forEach(row, newIndex) => {
    const oldIndex = grid.rows.indexOf(row);
    grid.rows.moveElement(oldIndex, newIndex);
    }


    This function uses the rows to sort everything. But the collectionview is not up to date after this sorting and things start to fail.
    Updating the collectionview puts everything back in its original order.

    Question:
    How do we prevent the collectionview putting everything back in its original order?
    Should we be sorting the rows on the grid or sorting the collectionview some other way?
  • Replied 18 September 2017, 4:33 am EST

    Hi,
    Please cancel default sorting before applying custom sorting by setting cancel property to true.


    grid.sortingColumn.addHandler(function(s,e){
    e.cancel=true;
    //custom sorting
    });


    Alternatively, you can also use sortComparer and sortConverter properties those accepts a callback. For more information, please refer to the documentation:
    [link]http://demos.wijmo.com/5/Angular/WijmoHelp/WijmoHelp/topic/wijmo.collections.CollectionView.Class.html[/link]


    Thanks,
    Manish Kumar Gupta
  • Replied 19 September 2017, 3:01 am EST

    Thanks for the reply.

    I dont think this will work for us. We created a grid with grouping so its hierarchical.
    We group our data on 2 columns (city and state). The state column isnt visible. When the user sorts on city we want the lower levels to be sorted on city and the parents on state.

    Your help is greatly appreciated
  • Marked as Answer

    Replied 20 September 2017, 2:22 am EST

    Hi,
    In this case, you need to push another column in sortDescriptions along with current column. Please refer to the fiddle[1] that implements the same.

    Thanks,
    Manish Kumar Gupta
  • Replied 20 September 2017, 4:54 am EST

    combination of sortDescriptions and sortConverter works for us. Thanks.
Need extra support?

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

Learn More

Forum Channels