Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Colour up rows with setHighlightConditions


Go to End


3 Posts   1701 Views

Avatar
carlossg

Community Member, 13 Posts

12 August 2008 at 10:48am

Hi all,
Trying to colour up some rows.
Let's say that we have the following has_many relation between employer and employee.
I want to show a has many table with all the employees and colour up those who are employed by the employer which we are working with in the CMS

Can anyone help me with this code?


class employee exteds DataObject {
   $has_one = array (
          'MyEmployer' => 'EmployerPage' 
     )
}



class EmployerPage exteds Page {

  $has_many = array (
     'Employees' => 'Employee'
   )
$MyTable = new HasManyComplexTableField(
			$this,
			'Employees',
			'Employee',
			array(
				'Name' => 'Name_label',				
			),
			'getCMSFields_forPopup'
	);        
      
		//Hightlighting
		$MyTable ->setHighlightConditions(array(
			array(
				'rule' => '$this->ID == $MyEmployerID',    //think the problem is that $this->ID don't gets the proper value when evaluated ?¿?¿
				'class' => 'orange'
			)
		));
}

Thanks a lot.

Avatar
Ingo

Forum Moderator, 801 Posts

14 August 2008 at 10:57pm

the highlight conditions are run through PHP's eval() function. in this case you're not in the original $this context, so $this->ID would resolve to TableListField isntead of your Employee class.
How about:

 $MyTable ->setHighlightConditions(array( 
         array( 
            'rule' => $this->ID . ' == $MyEmployerID',
            'class' => 'orange' 
         ) 
      )); 

Avatar
carlossg

Community Member, 13 Posts

15 August 2008 at 6:05am

Ohhh, that simple!!!

Thanks a lot Ingo, I always get confused with the quotation and eval string.