Additional parameters in returned Json

Issue #54 wontfix
Former user created an issue

Hi guys,

I am using Datatables with additional module called yadcf which provide some nice filtering to the table. My issue was to add additional parameters to returned Json. I fixed it by adding additional function:

def expand_returned_json(self,ret):
    # here you may append additional parameters
    return ret

def get_context_data(self, *args, **kwargs):
             .
             .
             ret = {'draw': int(self._querydict.get('draw', 0)),
                   'recordsTotal': total_records,
                   'recordsFiltered': total_display_records,
                   'data': data
                   }
        return self.expand_returned_json(ret)
    except Exception as e:
        return self.handle_exception(e)

Usage: def expand_returned_json(self, ret):

    ret ['yadcf_data_0'] = ["KHTML","Webkit","Trident","Misc","Other browsers","Tasman","Presto","Gecko"]   
    return ret

Comments (2)

  1. David Wasylciw

    In the past I've just overridden get_context_data and added filter values there to use yadcf. As in:

    def get_context_data(self, *args, **kwargs):
        context = super(DatatableViewJson, self).get_context_data(**kwargs)
        context['yadcf_data_1'] = blah
        return context
    
  2. Maciej Wisniowski repo owner

    I think that the solution provided by @dwasyl is good enough. Just override get_context_data and use super()

  3. Log in to comment