Page 1 of 1

Formatting records based on content?

PostPosted: Sun Nov 11, 2007 5:47 pm
by macassist
Hi there, me again,

is it possible to format records (like colour them red) based on the value of one of the record's fields? For the sales reports I mentioned in my previous post, we need to highlight sales of quantity zero, as that indicates orders from customers which haven't been able to be supplied (this is for a wholesaler selling through other wholesalers).

Any thought very welcome.

Sean

PostPosted: Sun Nov 11, 2007 6:33 pm
by shannah
Yes. You can implement the css__tableRowClass() method in the delegate class. This is meant to return a CSS class that can be applied to the row for that record.

e.g.

Code: Select all
function css__tableRowClass(&$record){
    if ( $record->val('approved') == 'YES' ){
        return 'approved-transaction-row';
    }
    else return '';
}


Then in your CSS file you could define some characteristics for rows with the class 'approved-transaction-row' applied to it:
e.g.
Code: Select all
    tr.approved-transaction-row {
        background-color: red;
    }


Beware that some versions of IE don't respect the background-color property on the tag, so you would probably have to do:

Code: Select all
    tr.approved-transaction-row td {
        background-color: red;
    }

i.e. apply the background color to the individual cells.

(IMHO IE 6 should be banned. It makes like difficult for us web developers).

-Steve

PostPosted: Mon Nov 12, 2007 6:42 pm
by macassist
Hi Steve,

thanks for the prompt reply.

I tried what you suggested, but it's not highlighting the zero qty sales - here are my code snippets...

in /tables/vwkly_sales/vwkly_sales.php

Code: Select all
class tables_vwkly_sales {
   function css__tableRowClass(&$record){
    if ( $record->val('sale_qty_hidden') == '0' ){
        return 'zero_sale_row';
    }
    else return '';
   }
   function block__before_nav_menu(){   
      df_display(array('prod'=>&$prod), 'menu.html');
   }
   function init(&$vwkly_sales){
      $auth =& Dataface_AuthenticationTool::getInstance();
      $user =& $auth->getLoggedInUser();
      if ( $user and $user->val('user_role') != 'ADMIN' ){
         // We apply the security filter to non admin users.
         $vwkly_sales->setSecurityFilter(array($user->val('user_filter_field')=>$user->val('user_filter_value')));
      }
   }
}

in /dataface/plone.css

Code: Select all
tr.zero_sale_row {
   background-color: red;
}


None of the zero qty sales are showing as red-backgrounded - is this a style conflict (maybe with the testing of whether it's an odd or even row)?

Any further help very much appreciated

Sean

PostPosted: Mon Nov 12, 2007 8:07 pm
by shannah
First thing to check is if the css class is actually getting applied. You can do this by checking the html source of the page and do a find for 'zero_sale_row'.

If it is getting applied but the rows are not showing up red, then it is a CSS issue.

If it is not getting applied then it is a PHP issue.

If you find that it is a CSS issue, refer to my note in my previous post about IE and its issues with background colors on tr tags.

If you find that it is a PHP issue, there are a couple of things you can do.

1. I notice that you are comparing the 'sale_qty_hidden' value to the string '0' rather than the integer 0. Is this intentional. Perhaps try the integer 0 instead.

2. You should place some debugging code inside the css__tableRowClass() method to make sure that it is being called. (i.e. add some echo statements and see if they show up in the resulting page --- if you do this make sure you check the html source for the output - not just the resulting page).

-Steve

PostPosted: Mon Nov 12, 2007 9:17 pm
by macassist
Hi Steve,

yes, the zero_sale_row is appearing in the source:

Code: Select all
class="listing odd zero_sale_row"


So it looks like the listing and odd classes are getting precedence.

Unfortunately, I'm no CSS guru, so if anyone can help me out with how to fix this CSS precedence issue, I'd be very appreciative.

Regards

Sean

PostPosted: Tue Nov 13, 2007 5:16 am
by shannah
Cascading stylesheets give the last style rule the precedence. If your rules are at the end of the plone.css file, then it will get the precedence, and not the odd class.

You can force precedence by adding '!important' after your rule.
e.g.
Code: Select all
tr.zero_sale_row { background-color: red !important}


justs in case something is overriding your setting.

Which browser are you using? As I mentioned before, IE may not respect background-color on a tr tag. You may have to change the rule to:

Code: Select all
tr.zero_sale_row td { background-color: red}


On a side note, it is not good practice to be altering the plone.css file directly. Better to make your own stylesheet and include it.
http://xataface.com/documentation/how-t ... avascripts

-Steve

PostPosted: Tue Nov 20, 2007 6:51 pm
by macassist
OK, got it working...

As a side note I've used custom_stylesheets, but that's not where the problem was - it was that I was using a hidden field for the validation. I've changed over to using 3 other fields (which, when the hidden field is zero, two of them are also 0 and the third is not empty) and the zero sale rows are now colored red (well, I used a lighter shade of red because I was getting cross-eyed with full red).

Thanks for the help, Steve.

Sean

PostPosted: Wed Jul 23, 2008 2:12 pm
by fantomasdm
for using css style sheet in relative rocord list?

PostPosted: Fri Jul 25, 2008 3:16 pm
by shannah
Currently the related record list isn't as flexible to deal with as the regular result list. So there is no way (off the top of my head) without actually modifying the xataface source to customize the class of a row.

Re: Formatting records based on content?

PostPosted: Mon Jun 21, 2010 10:38 am
by jvinolas
Hi,

I have one problem: the code only works if I use:
Code: Select all
tr.baixa-row td { background-color: red;}


Does nothing with your code:
Code: Select all
tr.baixa-row { background-color: red;}


But the problem is that, when it works (with td format), only changes background of first field (checkbox), not all the row. Is it possible to get all the row rendered as well?

Thanks.

Re: Formatting records based on content?

PostPosted: Mon Jun 21, 2010 10:45 am
by shannah
Yes... I think IE doesn't let you apply backgrounds to tr tags (I would have though they would support this by IE 8, but maybe not).

Not sure why it's not updating the color of all of your rows. It's hard to comment without looking directly at the HTML that is produced to know if the CSS should be working.

You may want to add a !important to your rule to make sure it's not getting overridden by later rules.

-Steve

Re: Formatting records based on content?

PostPosted: Tue Jul 06, 2010 10:31 am
by jvinolas
It was the !important command. Thanks a lot!

Re: Formatting records based on content?

PostPosted: Mon Sep 03, 2012 9:03 pm
by rtresidd
Hi Steve
I was trying to use this particular method for working on rows of related records.. but no methods existed in the php to handle this..
So I've added some code to be able to assign a css handler for a related record based on the related records relationship name.
seems to work and others may find it useful:
In RelatedList.php:
In the function "toHtml()" :around line 432 (version 1.9 3856)
just prior to the code:
echo "<tr class=\"listing $rowClass\" style=\"$style\" id=\"row_$rrecid\">";
add :

Code: Select all
$rowClass .= ' '.$this->getRelatedRowClass($rrec, $this->_relationship_name);



Then add in this function to the same file:

Code: Select all
   
        function getRelatedRowClass(&$record, &$relationship_name){
      $del =& $this->_table->getDelegate();
      $functionName = 'css__relatedTableRowClass_' . $relationship_name;
      if ( isset($del) and method_exists($del, $functionName ) ){
         return $del->$functionName ($record);
      }
      return '';
   }


now in the delegate php file you can do something like:

Code: Select all
  function css__relatedTableRowClass_RELATIONSHIP_NAME( &$record ){
      if ( $record->val('BoardModStatus') == 'Outstanding' ) return 'outstanding-mods-row';
      else return '';
  }


I'm really beginning to like this interface :)

Cheers
Richard

Re: Formatting records based on content?

PostPosted: Sat Sep 08, 2012 10:31 am
by shannah
Good solution. I have added it to the issue tracker so hopefully I can get this in for the next release.

http://bugs.weblite.ca/view.php?id=1148

One piece of optimization is that you don't actually need to pass the relationship name as the 2nd parameter since the first parameter is a Dataface_RelatedRecord object, and it contains a reference to the relationship.

E.g.
Code: Select all
$rowClass .= ' '.$this->getRelatedRowClass($rrec);


And
Code: Select all
function getRelatedRowClass(&$record){
      $relationship_name = $record->_relationshipName;
      $del =& $this->_table->getDelegate();
      $functionName = 'css__relatedTableRowClass_' . $relationship_name;
      if ( isset($del) and method_exists($del, $functionName ) ){
         return $del->$functionName ($record);
      }
      return '';
   }

Re: Formatting records based on content?

PostPosted: Tue Sep 11, 2012 2:05 am
by rtresidd
Hi Steve
Cheers for the optimization. I'm doing most of my editing in a notepad++ and unfortunately I'm still figuring out what is available in each class etc :)
I'm still rather new to php and don't really have a nicer editing environment...

Thanks
Richard