Пример #1
1
 /**
  * Renders the data cell content.
  *
  * @param integer $row the row number (zero-based)
  * @param YdActiveRecord $data the data associated with the row
  */
 protected function renderDataCellContent($row, $data)
 {
     ob_start();
     parent::renderDataCellContent($row, $data);
     $parentContents = ob_get_clean();
     if ($data instanceof CActiveRecord) {
         $links = is_callable(array($data, 'getMenuLinks')) ? call_user_func(array($data, 'getMenuLinks')) : array();
         if ($links) {
             if (is_callable(array($data, 'getUrl'))) {
                 $this->buttonOptions['type'] = TbHtml::BUTTON_TYPE_LINK;
                 $this->buttonOptions['url'] = call_user_func(array($data, 'getUrl'));
             }
             echo '<div class="filter-container">';
             $this->buttonOptions['split'] = true;
             echo TbHtml::buttonDropdown($parentContents, $links, $this->buttonOptions);
             echo '</div>';
         } else {
             $url = is_callable(array($data, 'getUrl')) ? call_user_func(array($data, 'getUrl')) : false;
             if ($url) {
                 $this->buttonOptions['class'] = isset($this->buttonOptions['class']) ? $this->buttonOptions['class'] . ' btn' : 'btn';
                 echo TbHtml::link($parentContents, $url, $this->buttonOptions);
             } else {
                 echo TbHtml::button($parentContents, $this->buttonOptions);
             }
         }
     } else {
         echo TbHtml::button($parentContents, $this->buttonOptions);
     }
 }
Пример #2
0
 protected function renderDataCellContent($row, $data)
 {
     ob_start();
     parent::renderDataCellContent($row, $data);
     $value = ob_get_clean();
     if (is_numeric($value)) {
         $this->total += $value;
     }
     echo $value;
 }
 public function renderDataCellContent($row, $data)
 {
     $isModel = $data instanceof CModel;
     if ($isModel) {
         $widgetClass = 'TbEditableField';
         $options = array('model' => $data, 'attribute' => empty($this->editable['attribute']) ? $this->name : $this->editable['attribute']);
         //if value defined in column config --> we should evaluate it
         //and pass to widget via `text` option: set flag `passText` = true
         $passText = !empty($this->value);
     } else {
         $widgetClass = 'TbEditable';
         $options = array('pk' => $data[$this->grid->dataProvider->keyField], 'name' => empty($this->editable['name']) ? $this->name : $this->editable['name']);
         $passText = true;
         //if autotext will be applied, do not pass `text` option (pass `value` instead)
         if (empty($this->value) && TbEditable::isAutotext($this->editable, isset($this->editable['type']) ? $this->editable['type'] : '')) {
             $options['value'] = $data[$this->name];
             $passText = false;
         }
     }
     //for live update
     $options['liveTarget'] = $this->grid->id;
     $options = CMap::mergeArray($this->editable, $options);
     //if value defined for column --> use it as element text
     if ($passText) {
         ob_start();
         parent::renderDataCellContent($row, $data);
         $text = ob_get_clean();
         $options['text'] = $text;
         $options['encode'] = false;
     }
     //apply may be a string expression, see https://github.com/vitalets/x-editable-yii/issues/33
     if (isset($options['apply']) && is_string($options['apply'])) {
         $options['apply'] = $this->evaluateExpression($options['apply'], array('data' => $data, 'row' => $row));
     }
     //evaluate htmlOptions inside editable config as they can depend on $data
     //see https://github.com/vitalets/x-editable-yii/issues/40
     if (isset($options['htmlOptions']) && is_array($options['htmlOptions'])) {
         foreach ($options['htmlOptions'] as $k => $v) {
             if (is_string($v) && (strpos($v, '$data') !== false || strpos($v, '$row') !== false)) {
                 $options['htmlOptions'][$k] = $this->evaluateExpression($v, array('data' => $data, 'row' => $row));
             }
         }
     }
     $this->grid->controller->widget($widgetClass, $options);
 }
 /**
  * Renders the data cell content.
  *
  * @param integer $row the row number (zero-based)
  * @param YdActiveRecord $data the data associated with the row
  */
 protected function renderDataCellContent($row, $data)
 {
     ob_start();
     parent::renderDataCellContent($row, $data);
     $parentContents = ob_get_clean();
     $links = array();
     if ($data instanceof CActiveRecord) {
         $links[] = array('label' => $parentContents, 'url' => $data->getUrl());
         $items = method_exists($data, 'getMenuLinks') ? call_user_func(array($data, 'getMenuLinks')) : array();
         if ($items) {
             $links[] = array('items' => $items);
         }
     } else {
         $links[] = $parentContents;
     }
     echo '<div class="filter-container">';
     Yii::app()->controller->widget('bootstrap.widgets.TbButtonGroup', array('buttons' => $links));
     echo '</div>';
 }
Пример #5
0
    /**
     *### .renderDataCellContent()
     */
    protected function renderDataCellContent($row, $data)
    {
        $options = CMap::mergeArray($this->editable, array('model' => $data, 'attribute' => $this->name, 'parentid' => $this->grid->id));
        //if value defined for column --> use it as element text
        if (strlen($this->value)) {
            ob_start();
            parent::renderDataCellContent($row, $data);
            $text = ob_get_clean();
            $options['text'] = $text;
            $options['encode'] = false;
        }
        /** @var $widget TbEditableField */
        $widget = $this->grid->controller->createWidget('TbEditableField', $options);
        $widget->buildHtmlOptions();
        $widget->buildJsOptions();
        $widget->registerAssets();
        //if editable not applied --> render original text
        if (!$widget->apply) {
            if (isset($text)) {
                echo $text;
            } else {
                parent::renderDataCellContent($row, $data);
            }
            return;
        }
        //manually make selector non unique to match all cells in column
        $selector = str_replace('\\', '_', get_class($widget->model)) . '_' . $widget->attribute;
        $widget->htmlOptions['rel'] = $selector;
        //can't call run() as it registers clientScript
        $widget->renderLink();
        //manually render client script (one for all cells in column)
        if (!$this->_isScriptRendered) {
            $script = $widget->registerClientScript();
            //use parent() as grid is totally replaced by new content
            Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->grid->id . $selector . '-event', '
							   $("#' . $this->grid->id . '").parent().on("ajaxUpdate.yiiGridView", "#' . $this->grid->id . '", function() {' . $script . '});
            ');
            $this->_isScriptRendered = true;
        }
    }
Пример #6
0
    /**
     *### .renderDataCellContent()
     */
    protected function renderDataCellContent($row, $data)
    {
        // #745 adding support for CArrayDataProviders only if based on a CModel array
        if (!$data instanceof CModel) {
            throw new CException('EditableColumn can be applied only to CModel based objects');
        }
        $options = CMap::mergeArray($this->editable, array('model' => $data, 'attribute' => $this->name, 'parentid' => $this->grid->id));
        //if value defined for column --> use it as element text
        if (strlen($this->value)) {
            ob_start();
            parent::renderDataCellContent($row, $data);
            $text = ob_get_clean();
            $options['text'] = $text;
            $options['encode'] = false;
        }
        /** @var $widget TbEditableField */
        $widget = $this->grid->controller->createWidget('TbEditableField', $options);
        //if editable not applied --> render original text
        if (!$widget->apply) {
            if (isset($text)) {
                echo $text;
            } else {
                parent::renderDataCellContent($row, $data);
            }
            return;
        }
        /* just add one editable call for all column cells */
        $widget->buildHtmlOptions();
        $widget->buildJsOptions();
        $widget->registerAssets();
        //can't call run() as it registers clientScript
        $widget->renderLink();
        //manually render client script (one for all cells in column)
        $selector = $widget->getSelector(false);
        if (!$this->isScriptRendered($selector)) {
            $script = $widget->registerClientScript(false);
            //use parent() as grid is totally replaced by new content
            Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->grid->id . '-' . $this->name . '-event', '
				$("#' . $this->grid->id . '").parent().on("ajaxUpdate.yiiGridView", "#' . $this->grid->id . '", function() {' . $script . '});
			');
        }
    }