Skip to content

Use of MultiTableMixin with Filtering #953

Open
@cdufse

Description

@cdufse

Hello,

Is it possible to have an evolution of this package django-tables2 for some things that can be very useful.
the goal : display several tables on a same page with all the abilities of the SingleTableMixin table.

class PersonTablesView(MultiTableMixin, TemplateView):
template_name = "multiTable.html"
tables = [
PersonHTMxTable(qs1), => from 1 table of person
CityHTMxTable(qs2), => from 1 table of cities
JobHTMxTable(qs3) => from 1 table of jobs
]
table_pagination = {
"per_page": 5
}

2 cases can be very useful:

  • 1 search bar to filter all the tables,
  • 1 search bar for each table displayed if several tables in a page.

I have this needs but i don't find any workaround to solve these 2 problems.

I use HTMx get request in django to define search bar.

In a single table case I can define this kind of class and it's working

class PersonTablesView(SingleTableMixin, FilterView):
table_class = PersonHTMxTable
queryset = Person.objects.all()
filterset_class = PersonFilter => a new class to filter in person table with field of search bar
paginate_by = 5
template_name = "singleTable.html"

My goal is to have this kind of thing working :

class PersonTablesView(MultiTableMixin, TemplateView, FilterView):
template_name = "multiTable.html"
tables = [
PersonHTMxTable(qs1), => from 1 table of person
CityHTMxTable(qs2), => from 1 table of cities
JobHTMxTable(qs3) => from 1 table of jobs
]
filters = [
PersonFilter, => a new class to filter in person table with field of search bar
CityFilter, => a new class to filter in cities table with field of search bar
JobFilter => a new class to filter in jobs table with field of search bar
]
table_pagination = {
"per_page": 5
}

if the same thing allow to search in the 3 filters or if 3 search things are use for each filters could be possible, using
1 or 3 boxes in html like this :

form hx-get="{% url 'my_request_htmx linking python class' %}" hx-target="div.table-container" hx-swap="outerHTML" hx-indicator=".progress" class="d-flex flex-row align-items-center flex-wrap"> /form

So is it possible to have a such evolution in the django-tables2 package ?
Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions