ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

Correct way to get Rank #70

Open kkcodes opened 5 years ago

kkcodes commented 5 years ago

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!

ypnos-web commented 5 years ago

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.