Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:01:32+00:00 2026-05-31T10:01:32+00:00

I would like to create a table with django-tables2 such that different rows have

  • 0

I would like to create a table with django-tables2 such that different rows have different properties.

By default I get either

<tr class="odd">

or

<tr class="even">

How can I specify my own class for some of the rows?

Similarly, if I have a CheckBoxColumn and I specify some data for this column, it goes into the value:

<input type="checkbox" name="col" value="123"/>

This is great for figuring out which checkbox was checked. However, how can I set some checkboxes as checked when the table is created?

My scenario: the user picks some rows from a large table. For example, the table has

  • orange 1
  • orange 2
  • apple 5
  • orange 3
  • apple 4
  • cucumber 7
  • aaple 1

The user picks aaple 5 and cucumber 7.

Then I would like to display all apples and all cucumbers, since the user picked at least one apple and at least one cucumber. This allows the user to see other relevant entries:

  • apple 5
  • apple 4
  • cucumber 7

However, I would like to highlight the entries actually picked by the user by using css and/or by displaying a checked checkbox:

  • apple 5
  • apple 4
  • cucumber 7
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:01:33+00:00Added an answer on May 31, 2026 at 10:01 am

    Well, let me post my own solution.

    I have copied the standard template table.html and edited it. I only changed one line:

    <tbody>
        {% for row in table.page.object_list|default:table.rows %} {# support pagination #}
        {% block table.tbody.row %}
        <tr class="{{ row.tr_class }}">  <!-- CLASS FOR EACH ROW -->
    

    instead of

        <tr class="{% cycle "odd" "even" %}">
    

    This way you can set a different class for each row in the table. It remains to add an invisible column to your table class:

    class MyTable(tables.Table):
      tr_class=tables.Column(visible=False)
      ... # other columns
    

    After that, whenever you are creating a table, you can set any CSS classes for any particular rows. Remember to use the modified template:

    {% render_table div_table "modifiedtable.html" %}  
    

    Of course, you can also change the original table.html.

    Can anybody suggest a more graceful solution?

    Overall, I have a feeling that django_tables2 is still missing many important features, so I have to reinvent the wheel every time I am trying to do something nontrivial.

    Define tr_class

    To use this, you must use custom rendering. For example:

    class MyTable(tables.Table):
     tr_class=tables.Column(visible=False, empty_values=())
     def render_tr_class(self, value):
       if value.chosen == True:
         return 'highlight'
    

    And the tr would be given the class highlight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that simplified looks like this: create table Test ( ValidFrom
I would like to create a table to store device settings. The table has
I would like to create an HTML table with row colors changing based on
I have created a test table in MySQL and would like to insert 10
I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I would like to create a table with multiple columns, each containing a button.
I would like to create my database tables in SMS then generate a script
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to create a database backed interactive AJAX webapp which has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.