kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Name of action column #150

Closed dan-developer closed 7 years ago

dan-developer commented 7 years ago

How to set a friendly name for the action column?

drop down action column

kartik-v commented 7 years ago

Set the header property of the action column to a string you need.

dan-developer commented 7 years ago

In this part of the code the column label is defined from the configuration array:

protected function getColumnLabel($key, $column)
    {
        if (is_string($column)) {
            $matches = $this->matchColumnString($column);
            $attribute = $matches[1];
            if (isset($matches[5])) {
                return $matches[5];
            } //header specified is in the format "attribute:format:label"
            return $this->getAttributeLabel($attribute);
        } else {
            $label = $key;
            if (is_array($column)) {
                if (!empty($column['label'])) {
                    $label = $column['label'];
                } elseif (!empty($column['header'])) {
                    $label = $column['header'];
                } elseif (!empty($column['attribute'])) {
                    $label = $this->getAttributeLabel($column['attribute']);
                } elseif (!empty($column['class'])) {
                    $class = explode("\\", $column['class']);
                    $label = Inflector::camel2words(end($class));
                }
            }
            return trim(strip_tags(str_replace(['<br>', '<br/>'], ' ', $label)));
        }
    }

This does not allow, for example, a dependency injection because the column is not instantiated before defining the label, for example:

\Yii::$container->set('tubaron\grid\DropDownActionColumn', [
    'dropdown' => true,
    'dropdownOptions' => [
        'class' => 'pull-right',
    ],
    'template' => '{view} {update}',
    'header' => Yii::t('tubaron', 'Ações'),
]);

It may not be a crucial thing, but it might make things more centralized, so it would be great if you had events in DynaGrid like EVENT_BEFORE_INIT, EVENT_AFTER_INIT, etc ... It's a suggestion.

Thank you.

githubjeka commented 7 years ago

Same too [DELETED] I can't get labels from Models,, need to copy to header colums. It's very very very bad..

kartik-v commented 7 years ago

@githubjeka would appreciate if you can share details of any issue and what your proposal is to overcome it in this extension, rather than just a critical remark from your end which is of no use or help.

@AndersonDan will need to study, understand and look into your proposed suggestion. Thanks for the suggestion.

githubjeka commented 7 years ago

Oh, sorry for this. I've got it all mixed up, your code correct.

I just thought of something that is not exist... REF https://github.com/yiisoft/yii2/issues/4504 https://github.com/yiisoft/yii2/pull/4738