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

BoundRow allow getting key and value for columns

Open hvdklauw opened this issue 14 years ago • 3 comments

Right now in the template you loop through the columns to display the headers.

Then you loop through the rows and for each row through the values.

It would have real added value if you could look through the values and also get the corresponding column name for that value. That way you can for instance add special conditions in your template to turn a value into a link or something like that.

So something like:

{% for column, value in item.iteritems %} ... {% endfor %}

instead of:

{% for value in item.values %} ... {% endfor %}

hvdklauw avatar Sep 07 '10 12:09 hvdklauw

I think me might be able to solve this using the changes in Kevin's branch (179fc7a4d04578fc93849a5d7755a7d97e7351db - see also the comments), which would allow something like:

{% for value in row %} {{ row.column }} {% endfor %}

miracle2k avatar Sep 23 '10 22:09 miracle2k

that allows you to set properties on the column and pass them to the different cells. What I need is in the template a way to know which column I'm currently outputting the value for.

You would have to modify it, to pass the colum object to the cell on lines 359 and 362. And ofcourse store it on the column init.

hvdklauw avatar Sep 24 '10 06:09 hvdklauw

Yes, that's the plan. Turns out Github doesn't show the comments in the above link, but you can see them here:

http://github.com/isolationism/django-tables/commit/179fc7a4d04578fc93849a5d7755a7d97e7351db

miracle2k avatar Sep 24 '10 08:09 miracle2k