Hello,
I hopelessly try to fix the following problem.
I have a view which holds nodes that have taxonomy terms. Depending on tid, I want the row to be a certain color.
For example if the node's taxonomy is set to 'moderate' then the row is highlighted green.
Following recommendations of issue #438138: Is it possible to display the tid as class in the unformatted style?, implementing garland_preprocess_hook with unformatted style in the garland template.php, clearing registry cache, but it doesn't work for me. I don't get the expected output, i. e. class="term-tid". I only get the usual template_preprocess_views_view_unformatted classes (views-row-first, views-row-odd views-row-even...)
Any and all help would be greatly appreciated.
Thanks
Comments
Comment #1
dwwThis sounds almost exactly like the row coloring of the issue queue views on this site, except we use the issue status field instead of a taxonomy term. #359122: Add an "Issue table" view style plugin to provide row coloring and the links at the top of the page is where we implemented that, and if you read that issue (and the patches there), that'll give you a good idea how to do this... Even if you don't do your own style plugin, the view template stuff we're doing in project_issue.module should be most of what you need. In particular, check out:
function project_issue_preprocess_views_view_table()from project_issue.module.Good luck,
-Derek
Comment #3
Oleksa-1 commenteddww,
for me it is still not clear how to put these classes . I am now trying to use same steps like in
function project_issue_preprocess_views_view_table() from project_issue.module
If in my table I have field_myfield - how to enter it in my function?
Comment #4
dwwYour field has to be in the result set from your view. So you need to add those fields (perhaps as hidden fields) into your view. Then they should start showing up in that $result object.
Comment #5
Oleksa-1 commentedHi, dww, it really works, but... In my view i have these fields:
Fields
* [field_gallery_status_value] == Content: Status (field_gallery_status)
* [title] == Node: Title
* [nid] == Node: Nid
* [name] == Taxonomy: Term
And only if i put field nid ($variables['row_classes'][$num][] = "priority-$result->nid ";), it is displayd in tr class (
<tr class="odd state- priority-2">), with all other fields (e.g. $variables['row_classes'][$num][] = "priority-$result->field_gallery_status_value";) it is empty (<tr class="odd state- priority- ">)I can not understand why ?
Comment #6
off commentedSubscribe
Comment #7
Oleksa-1 commented@OFF
all this snippets not needed anymore
there is module
views tablehighlighter
Comment #8
off commentedI just have how to solved this problem:
function iid_preprocess_views_view_table($variables) {
$view = $variables['view'];
if ($view->plugin_name == 'table') {
foreach ($view->result as $num => $result) {
$variables['row_classes'][$num][] = "$result->nid";
print_r($result);
}
}
$variables['class'] .= " table";
}
But thanks for the module, I'm going to trying this.
Comment #9
Sinan Erdem commentedI really have a neat solution for this.
1. Activate module: http://drupal.org/project/color_field
2. Add a color field named "color" to taxonomy entity. (Got to taxonomy->manage fields)
3. Determine some colors for your terms by editing them.
4. In your view, add relationship "Content: Taxonomy terms on node"
5. Add taxonomy:color as a field, and exclude it from display.
6. In views format, table settings, add "color-[field_color]" for the "Row class".
7. Add a "Global text field" to the header of the view.
8. Choose "Text Format" as "Fully HTML" and paste below JS code into text area (just remember to change YOUR-VIEW-CLASS to your view's class):
Comment #10
Sinan Erdem commentedUpdate to previous comment:
The code was not working for the items loaded via AJAX (pager or exposed filters, etc). I added the same code also after AJAX load is finished. Latest code is here:
Comment #11
runeasgar commentedI am not certain this is relevant, but here's how I'm highlighting my issue tracker rows: