You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I am using POST method, the default global search and column search is not working. The same worked when I used GET method and ViewSet. Then I changed the method to POST using ListAPIView. Then its not filtering based on the search parameters. Its giving complete list without filtering.
The text was updated successfully, but these errors were encountered:
@NAYcoder I had a similar issue, I had to change a datatables from GET to POST because I was hitting URL Length limits on my server. I had to do two things:
On client side I had to inject the csrf token on the POST call:
<html>
...
<! -- django renders this as an input -->
{% csrf_token %}
...
</html<script>// get the token valueconsttoken=$('input[name="csrfmiddlewaretoken"]').val();constextraData=(data)=>{// Add the CSRF token to the data form so it's not blocked by Djangodata.csrfmiddlewaretoken=token;returndata;};consttable=newDataTable({ajax: {url: 'my/api/url?format=datatables',method: 'POST',data: extraData,},/// .. other things});</script>
On the server side, I was using ReadOnlyViewSet, I had to re-wire it to use ModelViewSet plus ListModelMixin:
classMyListAPI(ListModelMixin, GenericViewSet):
queryset=models.MyModel.objects.all()
serializer_class=serializers.MyModelSerializerdefcreate(self, request, *args, **kwargs):
"""Rewire the create method to allow listing using POST method. """returnsuper().list(request, *args, **kwargs)
When I am using POST method, the default global search and column search is not working. The same worked when I used GET method and ViewSet. Then I changed the method to POST using ListAPIView. Then its not filtering based on the search parameters. Its giving complete list without filtering.
The text was updated successfully, but these errors were encountered: