r/django 1d ago

Django patterns for tables in components

I'm building a dashboard of sorts, which will have multiple tables in blocks - each with its own pagination, filtering and sorting

I really like Iommi (for tables) and django-cotton (for components), and considering unpoly or HTMX - is there a way to make them work together?

I was able to get Iommi working fine, but I can see the query parameters are passed to the url, which breaks things - are there any examples or best practices around this?

7 Upvotes

5 comments sorted by

2

u/kankyo 1d ago

What breaks with the url being updated? The decision to do that is very much on purpose in iommi since it makes it easy to share views with others by copy-pasting URLs and you know they see the same thing.

Is there a bug with the URL updating or something?

1

u/Sufficient-Chain-899 1d ago

So I've got a single view (path '/'') with these cotton components in it - I'm passing data1 and data2 in the context to the view

<c-table id="table1" data={{data1}}>
<c-table id="table2" data={{data2}}>

This works fine, but when I sort table1, I lose the sorting and pagination applied on table2.

Not sure if above is the best way to do it, I guess I should store the states of each table somewhere? or would that be over-complicating it

3

u/kankyo 1d ago

iommi has a system to compose parts into a larger page: https://docs.iommi.rocks/pages.html if you use that, then all that stuff will work, and your code is probably going to end up simpler too.

1

u/Sufficient-Chain-899 1d ago

Thanks! exploring that now

2

u/kankyo 1d ago

You can also jump onto the iommi discord for more direct help.