morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
204 stars 64 forks source link

client side filtering and sorting #122

Closed Conni2461 closed 9 months ago

Conni2461 commented 9 months ago

hey, afaik it is currently only possible to do filtering and sorting with ajax calls to the rest api.

Are there any plans to have client side filtering/sorting or is this already possible and i missed it in the docs.

The problem is that we have a really bit table that we are displaying and we have a filter form in front of the table. So e.g. you search for all Customers with a specific zip_code, then we render the datatable with that filter applied and get values back rather fast (max 3-5s).

But now i have a table with sort/filter inputs, and doing a filtering using an input, hits the database again which then (for some reason) takes up to 30 seconds even though the table is already prefiltered client side and only contains a couple of hundred rows. So all of this should be possible to do client side. Same for sorting.

It feels like our server is doing the same work over and over, with no debouncing, so if i have a input field and i enter e.g. New York in the column city it will end up sending 8 request which isn't great.

morlandi commented 9 months ago

Hello @Conni2461 ... I have no plan for client-side rendering .. the reason is that this library's exact purpose is to fill the gap between datatables.net and Django when server-side queries are involved during the interaction with the user.

However, sooner or later I might add support for debouncing in filters ... that would be useful on some occasions.

In your case, I think you have good opportunities to greatly speed up db lookups by adding select_related() and/or prefetch_related() to reduce the number of "secondary queries".

You can do it by overriding get_initial_queryset()

Conni2461 commented 9 months ago

In your case, I think you have good opportunities to greatly speed up db lookups by adding select_related() and/or prefetch_related() to reduce the number of "secondary queries".

You can do it by overriding get_initial_queryset()

we are already doing this, without much success. Okay thanks for your response, i'll try to find another solution.

Is there any chance that if i come up with a client-side filter/sorting solution, would you accept a PR?

morlandi commented 9 months ago

Thank you @Conni2461 .. to be honest, I would rather stay with Ajax to limit the complexity of the library. If the underlying table is small, you can always use a page size big enough to obtain one single page ... Filtering and sorting a small table server-side must always be very fast

Don't get me wrong ... I really appreciate your interest and proposal ... however, I can dedicate a limited amount of time to maintaining the library, which is already used in several projects, so I need to make precise choices and keep the complexity under control. Sometimes I risk being rude due to my rather limited English ... I do apologize for this

morlandi commented 9 months ago

On the other side, I would consider PR about filters debouncing ;)

Conni2461 commented 9 months ago

Don't get me wrong ... I really appreciate your interest and proposal ...

as a open source maintainer, i totally get it. Thats why i am asking before opening a +1000Lines PR or something like that ^^ (I know that feeling)

Still thanks for your time and input :) I'll probably look into a debounce PR. None the less but i don't see this part of this issue so i would close this as "Wont fix"

morlandi commented 9 months ago

Label "wont' fix" added ;)

Conni2461 commented 8 months ago

just fyi i improved it by a factor of 5 by optimizing the initial query myself using prefetch_related on more tables and then setting disable_queryset_optimization_only = True, latter was kinda key :) to get that 5x speed just because the slow example has deeply nested tables and the deferred was causing problems.

Thanks for allowing to disable this optimization :)

so i probably no longer have a need for this (it was my problem all along ^^) so i'll probably work on debounce sooner rather than later :)