django-tables2 icon indicating copy to clipboard operation
django-tables2 copied to clipboard

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

Open onno-timmerman opened this issue 7 months ago • 0 comments

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:

  • Simplifies targeting and manipulation of table rows and cells with htmx.
  • Reduces the need for manual ID assignments, streamlining the development process.
  • Enhances the ability to dynamically update table content with precision.

onno-timmerman avatar Jul 28 '24 13:07 onno-timmerman