Prado\Web\UI\WebControls\TDataList::applyItemStyles PHP Method

applyItemStyles() protected method

Item styles are applied in a hierarchical way. Style in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle}, {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}. Therefore, if background color is set as red in {@link getItemStyle ItemStyle}, {@link getEditItemStyle EditItemStyle} will also have red background color unless it is set to a different value explicitly.
protected applyItemStyles ( )
    protected function applyItemStyles()
    {
        $itemStyle = $this->getViewState('ItemStyle', null);
        $alternatingItemStyle = $this->getViewState('AlternatingItemStyle', null);
        if ($itemStyle !== null) {
            if ($alternatingItemStyle === null) {
                $alternatingItemStyle = $itemStyle;
            } else {
                $alternatingItemStyle->mergeWith($itemStyle);
            }
        }
        $selectedItemStyle = $this->getViewState('SelectedItemStyle', null);
        $editItemStyle = $this->getViewState('EditItemStyle', null);
        if ($selectedItemStyle !== null) {
            if ($editItemStyle === null) {
                $editItemStyle = $selectedItemStyle;
            } else {
                $editItemStyle->mergeWith($selectedItemStyle);
            }
        }
        // apply header style if any
        if ($this->_header !== null && $this->_header instanceof IStyleable) {
            if ($headerStyle = $this->getViewState('HeaderStyle', null)) {
                $this->_header->getStyle()->mergeWith($headerStyle);
            }
        }
        // apply footer style if any
        if ($this->_footer !== null && $this->_footer instanceof IStyleable) {
            if ($footerStyle = $this->getViewState('FooterStyle', null)) {
                $this->_footer->getStyle()->mergeWith($footerStyle);
            }
        }
        $selectedIndex = $this->getSelectedItemIndex();
        $editIndex = $this->getEditItemIndex();
        // apply item styles if any
        foreach ($this->getItems() as $index => $item) {
            if ($index === $editIndex) {
                $style = $editItemStyle;
            } else {
                if ($index === $selectedIndex) {
                    $style = $selectedItemStyle;
                } else {
                    if ($index % 2 === 0) {
                        $style = $itemStyle;
                    } else {
                        $style = $alternatingItemStyle;
                    }
                }
            }
            if ($style && $item instanceof IStyleable) {
                $item->getStyle()->mergeWith($style);
            }
        }
        // apply separator style if any
        if (($separatorStyle = $this->getViewState('SeparatorStyle', null)) !== null && $this->getHasSeparators()) {
            $controls = $this->getControls();
            $count = $controls->getCount();
            for ($i = $this->_header ? 2 : 1; $i < $count; $i += 2) {
                if (($separator = $controls->itemAt($i)) instanceof IStyleable) {
                    $separator->getStyle()->mergeWith($separatorStyle);
                }
            }
        }
    }
TDataList