Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Colour up rows with setHighlightConditions

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

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

Page: 1
Go to End
Author Topic: 1157 Views
  • carlossg
    Avatar
    Community Member
    13 Posts

    Colour up rows with setHighlightConditions Link to this post

    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.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Colour up rows with setHighlightConditions Link to this post

    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'
    )
    ));

  • carlossg
    Avatar
    Community Member
    13 Posts

    Re: Colour up rows with setHighlightConditions Link to this post

    Ohhh, that simple!!!

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

    1157 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.