0

In angular slickgrid, column wise sort asc/desc working fine. But removing sort by column header menu not working properly. When i remove the sort, the dataset should be reset to initially loaded dataview. But it maintaining the last sorting order. When i clear the all sorting by grid menu, it working fine. Here i shared my issue case as gif file, anyone please assist me to solve this issue.

enter image description here

Nelson Gnanaraj
  • 176
  • 1
  • 13
  • I understand your question because I'm the author of Angular-Slickgrid but please note that your question was flagged to be "closed". The reason is because you didn't include any code in your question and typically that doesn't demonstrate that you have done some effort before asking your question, it's always better to provide some code to provide context to the next person reading your question. So please keep that in mind since you are new on Stack Overflow. – ghiscoding Jun 21 '20 at 19:59
  • Dear @ghiscoding, thanks for your answer. i tried dataview refresh and resort. but not working for mw. So i tried `this.angular Grid.sort Service.clearSorting()`. this working fine for my case. If i ask any question means i will share my code snippet. – Nelson Gnanaraj Jun 22 '20 at 06:08

1 Answers1

1

You can call dataView.reSort(); to force a resort, that seems to be what you're looking for. The Grid Menu calls dataView.refresh(); and I'm not sure if that would trigger a reSort by the core lib, maybe it does. The header menu only removes a column sort without knowing if there's any sorting left, it basically doesn't keep track of of how many sorting are left and it won't call a reSort neither a refresh but you can call it yourself it will only tell the DataView hey please remove the sort of this column.

Now to add an extra process to the header menu, you'll need to subscribe to the clear-sort header menu command, you can do so by doing something like this (I did not tested it but it should work)

this.gridOptions = {
   headerMenu: {
     onCommand: (e, args) => {
       if (args.command === 'clear-sort') {
         const dataView = args.grid.getData();
         const sortCols = args.grid.getSortColumns();

         // add logic to know if this is last column sort 
         if (sortCols.length === 0) {
           // then call "refresh" or "reSort" either or
           // dataView.refresh();
           dataView.reSort();

           // if that doesn't work then try to call lib SortService from (onAngularGridCreated)
           // this.angularGrid.sortService.clearSorting();
         }
       }
   }
}  

Note that I'm the author of Angular-Slickgrid and this solution is not part of the lib itself, I might add it later but for now that should be a possible temporary solution.

ghiscoding
  • 12,308
  • 6
  • 69
  • 112