prepare_results should be able to return extra data apart from aaData to get_context_data

Issue #19 invalid
Nikita Pchelin created an issue

My use case is that I would like to calculate subtotals for one of the columns I return from prepare_results. My understanding is that I can do so by appending a value to the dictionary that is returned to the JavaScript code, but prepare_results does not have access to it, so it seems to be impossible right now.

Comments (3)

  1. Maciej Wisniowski repo owner

    I don't fully understand the issue there. If you want to append a dictionary to final data dictionary returned from the view then you can just override get_context_data method.

  2. Nikita Pchelin reporter

    Thank you Maciej, you are right, I should have looked at the code better. I've done:

        def get_context_data(self, *args, **kwargs):
            r = super(BaseDatatableView, self).get_context_data(*args, **kwargs)
            r['total'] = self.total
            return r
    

    ... and I've assigned self.total in prepare_results.

  3. Log in to comment