jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.86k stars 426 forks source link

HTMX auto id table, tr, td (feature request) #954

Open onno-timmerman opened 1 month ago

onno-timmerman commented 1 month ago

Feature Request: Automatic ID Assignment for TR and TD Elements for HTMX use cases

Summary:

There should be an easy way, or a default setting, for each <tr> element in the table to receive an ID derived from the record. Similarly, each <td> element should also have a unique ID.

Use Case:

Having unique IDs for table rows and cells greatly simplifies the process of targeting specific elements for operations such as updates or deletions. This is particularly useful when using htmx to dynamically replace or update parts of a table.

Current Practice:

Currently, I manually assign IDs to elements, e.g., <tr id="somemodelname-id"> where id is the primary key from the database. This approach makes it easy to target and manipulate elements with htmx.

Similarly, for cells, I use <td id="modelname-cellname-id"> to uniquely identify and target any cell.

Request:

  1. Automatic ID Assignment for <tr> Elements: Each table row should automatically receive an ID in the format <tr id="modelname-id">, where id is the primary key of the record.

  2. Automatic ID Assignment for <td> Elements: Each table cell should automatically receive an ID in the format <td id="modelname-cellname-id">, where cellname is the name of the field and id is the primary key of the record.

  3. Component Accessibility: There should be a way to access the component that renders the <tr> elements, allowing for easy replacement or updates of the entire row when needed.

Benefits: