cakephp-datatables
cakephp-datatables copied to clipboard
Correct way to get Rank
Hi,
I want to get the rank for each user based on points. This is what I have followed:
http://live.datatables.net/bexupefa/1/edit
And it works fine, but when I perform the search, the ranking goes wrong, because the search result returns a certain set of the result and based on that the new ranking is generated.
I do have a custom query with me, that is calculating the rank, but I am not sure, how to use that with this plugin.
Any guidance is appreciated!
Yes, if you use server-side processing you will also need to compute the rank on the server.
- Write a custom finder in your Table class, e.g.
findWithRank(…)
that includes an extra field (e.g. by using your custom query as a subquery) - In controller, provide the name of your custom finder as an argument to the component's
find()
- Configure the field as with any other field as a dt column
If the rank is independent from the request, you might also want to look into making it a virtual property of your Entity class.