Sorting tables when multiple tables in view (django-tables2)

Is it possible to sort two (or more) tables independently in the same view?

I have two tables in a view, one through the CBV SingleTableView (table A) and the other through the context (table B). When trying to sort table B, the correct url is passed eg. https //:..../? sort = delivery_date, however it appears to be consumed by table A. If the column name does not exist in table A, nothing happens if it does exist in table A, sorting table A and not table A.

I can understand this behavior since nothing has been posted to identify the original table. My question is, is there support for independently sorting multiple tables per view?

Thanks in advance Nathan

+3


source to share


1 answer


Well it was easy ...

Of course it was in the docs: I needed to add a prefix to my second table:



...
config = RequestConfig(self.request)
table2 = ot.UnfulfilledSalesOrderTable(om.SalesOrder.objects.filter(
    status__fulfilled=False, status__cancelled=False), self.request,
    prefix="2-")
config.configure(table2)
...

      

This adds a prefix to the querystring, such as the one ?sort=ship_date&2-sort=number

that provides exactly the functionality I get after.

+3


source







All Articles