dgriddstore

OnDemandGrid column sorting isn't working with dstore/Rest and Django Rest Framework


I have created an OnDemandGrid but noticed that the column sorts weren't working on any column. The arrows are there and the screen refreshes, but it won't sort the columns in asc or desc order. I have even tried specifying for each column but it still doesn't work. Anybody having/had the same issue?

UPDATE: 6.16.15 - After trying sortParam suggestion: Comment below explains. It appears to be doing the right thing... but still won't sort.

enter image description here

UPDATE 6.16.15 - 4:00pm Apparently ANY type of filtering or sort doesn't work well with Django - trying to determine how set filtering where dojo can communicate to Django Rest or vice versa - so far haven't been able to find a setting on either side that works. Not only does column sort not work - creating a search field doesn't work, nor creating a sort button.

enter image description here

This is after changing to the ORDERING_PARAM in DJANGO settings.py to 'SORT'... for all intensive purposes this looks like it should work.


Solution

  • A quick search through the Django Rest Framework documentation reveals that it defaults to expecting an ordering query parameter to indicate which field should be sorted. The dstore/Request store (inherited by Rest) allows you to indicate the query parameter name that sends sort information, via sortParam.

    Additionally, it appears that DRF's OrderingFilter indicates ascending sort with no prefix, and descending sort with -. dstore/Request defaults to expecting + and - as prefixes, but these can be overridden via ascendingPrefix and descendingPrefix.

    So in your case, you'll want to include sortParam: 'ordering', ascendingPrefix: '' in the properties passed when you create your Rest store instance.

    In general, when you run into store-related issues like this where the grid and backend don't seem to be making ends meet, this is the process you'll have to follow - find out what the server expects, find out what the client-side store implements, and see if it can be tweaked or needs to be customized.

    UPDATE 6.17.15 - Changing server side settings to match dojo/dgrid parameters -

    REST_FRAMEWORK = {
        'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
        'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
     #   'PAGE_SIZE': 25,
        'ORDERING_PARAM': 'sort'