Closed Bhoft closed 9 years ago
Yes you may want to check if there is a better way with the yii devs.
One alternative/workaround is to use a global helper function:
use yii\helpers\ArrayHelper;
class KvGlobal {
public static function getGridOptions($options = []) {
// you can set the default options in Yii::$app->params as well for easier config
$defaultOptions = [
'tableOptions' => [
'class' => 'table table-hover table-striped table-bordered',
],
'pager' => [
'firstPageLabel'=> kartik\icons\Icon::show('fast-backward', ['class' => ''], kartik\icons\Icon::BSG),
'lastPageLabel'=> kartik\icons\Icon::show('fast-forward', ['class' => ''], kartik\icons\Icon::BSG),
'prevPageLabel'=> kartik\icons\Icon::show('chevron-left', ['class' => ''], kartik\icons\Icon::BSG),
'nextPageLabel'=> kartik\icons\Icon::show('chevron-right', ['class' => ''], kartik\icons\Icon::BSG),
],
];
return ArrayHelper::merge($defaultOptions, $options);
}
}
Then use the above in your grid widgets at runtime:
use kartik\grid\GridView;
$options = KvGlobal::getGridOptions([
'dataProvider' => $dataProvider,
'columns' => $columns
]);
echo GridView::widget($options);
Hi I wanted to set the default icons for all paginations for gridviews. Therefore i added this to my bootstrap.php
But then i get Notices which aren't from your code but from the yii src.
Because the Html::tag uses encoding and tries to get the Yii::$app->charset which isn't set at this position. I don't know if there is a better position instead of the bootstrap.php
Problem if I add the code in the layout.php its maybe not used when i have a different view file for ajax requests. And in yii1.x i could set global settings for classes with the widgetFactory.
do you have a suggestion?
regards Horizons