Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.6
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
21 May 2008 at 17:26 UTC
Updated:
1 Sep 2015 at 13:10 UTC
Jump to comment: Most recent
Comments
Comment #1
moshe weitzman commentedViews does not support this yet. But it could nicely do this, and I think it would be useful. I suggest that this be a Row style for tables just like Lists have. The resulting row style form would probably just be a php textarea that gets the $row as input variable. The php should emit a class to be added to the row. Maybe this feature could put classes on cells as well.
It would be up to the author to add css that colors the row according to the class. Or Views could provide this?
Comment #2
merlinofchaos commentedYou can do this without a row style just be implementing THEMENAME_preprocess_views_view_table__VIEWNAME(&$vars).
You could go through the rows and add a class as you need. Then in views-view-table--viewname.tpl.php make sure that class is applied; you may not need the .tpl file at all as I believe there is already a variable for a row class, but I can't remember for sure.
This is the kind of thing I shy away from making UI widgets for, because there is a slippery slope I am worried about sliding falling down here. So this is the sort of thing that should be done via theming.
Comment #3
PMatwyuk commentedThanks for the info Moshe!
I'll definately be looking into making this happen, however since we're on the topic of Views perhaps you could tell me if there is a feature I need, in existance.
What I'm looking for is the ability to change the value of the data right from the view itself.
So using the above example say I'm looking at a view of projects, and status is one of the fields I can see. I notice theres one that's completed but is listed as being active. I want to be able to switch it right there in the view from active to complete and update on the spot. This would save me from having to click that project, editing the project and saving the project.
Yes I know its not that hard to go in by why have 4+ clicks when you can have 1? It would also be handy to just allow admins or project managers have this function however I do believe that could easily be done in the hook_perm().
Again any and all information is greatly appreciated, thanks for the quick reply on this one :)
Comment #4
PMatwyuk commentedThanks merlin, I'll definately be giving this a try. :)
Comment #5
merlinofchaos commentedViews doesn't support forms at all just now, though that's a planned future feature.
That said, you could probably put a form in the row style with theming, I think.
Comment #6
appel commentedI wanted to assign a class to all 'fixed' items in my table view.
Here's how I did it:
This code should be put in template.php.
Comment #7
mimisiku commentedI have the same problem, but this piece of code didn't worked for me. I am a beginer in PHP and Drupal and maybe i mised a thing:
function theme_views_view_table_frontpage($view, $nodes, $type) {
$fields = _views_get_fields();
foreach ($nodes as $node) {
$row = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
if($node->node_data_field_promovare == Promo)
{
$cell['class'] = "view-field". views_css_safe('-promo');
}
else
{
$cell['class'] = "view-field ". views_css_safe('-vip');
}
$row[] = $cell;
}
}
$rows[] = $row;
}
return theme('table', $view->table_header, $rows);
}
all the clases were made view-field-vip .... none of theme view-field-promo ... any sugestions ?
Comment #8
Anonymous (not verified) commentedI got this to work using the snippet below. But my question is, can I inlcude multiple views in it? Or do I have to create an override for each view:
Comment #9
merlinofchaos commentedYou can always override just theme_views_view_table and get all tables.
Comment #10
Anonymous (not verified) commentedThanks that worked for me, marking this issue fixed.
Comment #11
Anonymous (not verified) commentedDoes this code snippet still work in views2? I tried to load it into my 6.x template.php file and it seems to have had no affect on my views tables.
Anyone have any ideas as to what might be different?
txcrew
Comment #12
Anonymous (not verified) commentedSorry, it is throwing an error, I had to empty the cache
Fatal error: Call to undefined function _views_get_fields()Comment #13
domesticat commentedClosed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.
Comment #14
dboulet commentedAll the snippets provided above are for Drupal 5, but theming views is much less straight forward in Drupal 6. Can someone point me in the right direction for implementing this in Views 6.x.-2.x?
Comment #15
dboulet commentedThis is proving to be very difficult in Drupal 6. I'm trying to use merlinofchaos' suggestion in #2 of using the view table preprocess function to add classes to the
$vars['row_classes']variable, but it is very difficult to base those classes on field data, since the original data in$vars['rows']is destroyed bytemplate_preprocess_views_view_table()and replaced with rendered field data. I am having to resort to implementinghook_theme()in my template.php file to override the preprocess functions, and then re-implement the entire preprocess function in my theme. Seems like a lot of work just to add a few classes to my table rows.All this would be much easier if the original preprocess function stored the original row results in the
$varsvariable, so that other preprocess functions can access them later on, would this be possible?Comment #16
merlinofchaos commentedThe original data is still available in $view->result -- does that help?
Comment #17
moshe weitzman commentedproject_issue module does this already and you can see it on drupal.org in these very queues.
Comment #18
dboulet commented@merlinofchaos, I tried using $view->result, but I couldn't find a way to consistently reference the result corresponding to each row. For example, if I use a grouping field in my view, each group is rendered as its own table, and
$vars['rows']will only contain the results for that particular group—meanwhile,$vars['view']->resultwill always contain all results for the entire view.@moshe_weitzman, thanks for the tip, I'll check out the Project issue module to see what I can learn from the way it handles views tables.
Comment #19
dboulet commentedI've looked at the Project issue module, and it uses data from
$vars['view']->resultin a preprocess function to add the class names. As i mentioned in my last post, this approach doesn't work when using a grouping field in your view. I've posted a patch that would allow a workaround for this problem, see #536994: Store row data for future use in views table preprocess functions.Comment #20
dboulet commentedWith #536994 commited, adding classes to table rows should be as easy as adding code which resembles the following example to your theme's template.php:
Comment #21
aren cambre commentedIs there a concept of cell classes? E.g., what if I wanted table cells to have different colors depending on their values?
Comment #22
dboulet commented@Aren Cambre, One way that you can do this is add the classes to the row, and then target specific cells in your CSS. For example:
Just replace 'classname' with the class and 'fieldname' with the name of the specific field.
Comment #23
dboulet commentedSetting back to fixed.
Comment #25
trevorkjorlien commented[deleted]
Comment #26
mitchell commentedSee also: Views Table Highlighter.
Comment #27
eabquina commentedHad a problem first the views table highlighter doesn't work on Simplenews HTML Mails that was generated through Emogrifier.
Then just recently, I realized that if I just copied the Views Table Highlighter .css classes to my theme, it works perfectly on the newsletters (simplenews) sent...