I have a column defined with a custom sort strategy. That is working fine when I manually sort the column. However I added sortingExpressions so that it would be sorted in first place by default. That isn't using the custom sort strategy but instead just using the default sorting strategy. I tried adding the strategy to the object passed in for sortingExpressions but its still not calling it.
I have:
How can I use my custom sort strategy with the sortingExpressions?
Thanks
Hello Katy,
Thank you for contacting Infragistics Community!
I have investigated the described behavior and I believe you will find the following sample I have prepared for you very helpful. As you can observe I’m passing a custom sorting strategy to the MarketNotion column. In order to be able to understand easier how this custom strategy operates I have templated the cells of the MarketNotion column so that on the left side you can observe the real values and on the right side - the values which is going to be compared and sorted. Using SortingExpressions I initially sort this column in descending order and I pass again the custom sorting strategy. As you can observe this is working exactly as expected and the custom strategy is applied. If this sample is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me for further investigation.
Looking forward to hearing from you.
Best Regards, Martin Evtimov Entry Level Software Developer Infragistics, Inc.
Thanks for the example. I have managed to figure out the problem is related to also using the state feature. What I have found is that when you save the state it does this
getFeatureState(context) { const sortingState = context.currGrid.sortingExpressions; sortingState.forEach(s => { delete s.strategy; delete s.owner; }); return { sorting: sortingState }; },
So at that point the strategy is deleted. This seems to be wrong logic as I am not sure why saving state would remove the sort strategy. I understand the sort strategy cant be included into the json but it seems like it should be removing those from a clone rather than the actual. Since on page load I save initial state so that if they make changes they can restore the original view it means that my sort is always dropped. Since atm my state saves before the data loads once data is loaded its already lost it.
Thank you for getting back to me!
After further investigation, I can verify that currently the igxGrid state does not save the custom sorting strategies out of the box. What I can suggest is submitting a feature request regarding this functionality in our GitHub repository here.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case.
This will give you the opportunity do directly communicate with our development team regarding the issue and get notifications whenever a new information is available.
Meanwhile I have modified the provided sample with a workaround that I believe you will find very helpful. As you can observe when the igxGridState is stored the igxGridSortingExpressions are saved as well. Afterwards, immediately after restoring the state (please observe that I have set false to the IgxGridState sorting options) I pass the stored sortingExpressions to the igxGrid. The essential part here is to loop through this expressions and to pass your custom strategies to the expressions for the appropriate columns.
Please let me know if you need any further information.
Hi Martin
Thanks for the example. I have got the workaround working.
In regard to the issue around it not being able to save the sort strategy I do understand that limitation, however it seems like a bug to me that just by using the getState method without even applying a new state that it would drop the existing sort strategies in that case.
Thanks for your assistance
Katy
Thanks for your response!
I’m glad that you got the workaround working!
I understand your concerns and my suggestion would be to log this behavior as an issue in our GitHub repository here. This will give you the opportunity do directly communicate with our development team regarding the issue and get notifications whenever a new information is available.
Please let me know if you need any further assistance regarding this matter.