I have a custom visual that sorts by various statistics, so I've added an object to my capabilities.json to let the user select how they want to sort and then manage the sorting of the resolved view model in my code based on these values.
The visual's codebase is pretty expansive but I'm happy to point you in the right direction if you want to review my implementation:
Note that in my capabilities.json, I'm actually using implicit sorting, and it looks like I forgot to set it to custom when I added in the sorting functionality that's there now. It's just forcing the dataViewMapping to sort by category when the data comes across from the data model and it subsequently doesn't get used like this due to the overrides detailed above anyway.
Hey @dm-p , thanks for the informative reply, I really appreciate it. The examples you gave were very interesting and illuminating.
I just have a small question. I've noticed that you are using a dataReductionAlgorithm of Top - 30,000 which will load the first 30,000 values.
Hypothetically, if I have a dataset with 50,000 values and I implement a custom sort like this. Will it sort only the first 30,000 values or will it sort through all 50,000 values, then return the top 30,000?
No probs! There's not many of us that do custom visuals on here so I try to jump in where I can.
I believe that anything managed in code with respect to sorting will have to work post-data load from Power BI, as you can't work on the dataViewMapping until the data comes across from the data model and it's populated.
We might need guidance from @v-evelk or someone else from the team around the specifics on this one as anything I can offer would be wild speculation, I'm afraid.
But if you did want my speculation, I'd hazard a guess at just getting the top N rows that Power BI decides to provide, and something in my brain is nagging at me as to why I used implicit sorting here. There appears to have been a conscious decision to have done it, from looking back at my commit history. I'd further speculate that I probably wanted to make sure that if we had multiple categories, that we ensured at least some of them would be fully loaded in if we sorted the data this way. A good lesson here for improving quality of my commit messages to describe 'why' rather than 'what'...