cakephp-datatables icon indicating copy to clipboard operation
cakephp-datatables copied to clipboard

Correct way to get Rank

Open kkcodes opened this issue 6 years ago • 1 comments

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!

kkcodes avatar Oct 03 '18 08:10 kkcodes

Yes, if you use server-side processing you will also need to compute the rank on the server.

  1. 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)
  2. In controller, provide the name of your custom finder as an argument to the component's find()
  3. 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.

ypnos-web avatar Oct 03 '18 10:10 ypnos-web