本文介绍了在 kartik dynagrid 中设置空文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 kartik dynagrid,我想设置一个文本,显示数据提供程序何时返回空
网格
echo DynaGrid::widget(['列' =>$列,'showPersonalize' =>真的,'emptyText'=>'Sorry all pr has priitems',////------------------这是我设置的'选项' =>['id' =>'assignsolic-grid'],'gridOptions' =>['选项' =>['id' =>'网格'],'数据提供者' =>$数据提供者,'过滤器模型' =>$搜索模型,'showPageSummary'=>false,'寻呼机' =>['firstPageLabel' =>'第一的','lastPageLabel' =>'最后的','maxButtonCount' =>10、],'面板' =>['类型' =>GridView::TYPE_PRIMARY,//'标题' =>'<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i></h3>','before'='=>'选择要分配请求的Prs,然后单击分配请求按钮','之后' =>Html::button(' <i class=" glyphicon glyphicon-road "></i> Assign Solicitation ', ['value' => Url::to('assignsolc'),'class' =>; 'btn btn-danger', 'id' => 'assignsolic']),'页脚' =>错误的],'工具栏' =>[['内容' =>'{dynagridFilter}{dynagridSort}{dynagrid}'],'{出口}','{切换数据}'],'pjax' =>真的,'有边界' =>错误的,'条纹' =>真的,'浓缩' =>真的,'响应' =>真的,'responsiveWrap' =>错误的,'containerOptions'=>['style'=>'overflow:scroll'],]]);
这会返回设置未知属性的错误:kartik\dynagrid\DynaGrid::emptyText How can I set the empty text
解决方案
可以直接在confi/main.php格式化组件中定义空显示的值
'components' =>[......'格式化程序' =>['类' =>'yii\i18n\格式化程序','日期格式' =>'dd.MM.yyyy','decimalSeparator' =>',','千分隔符' =>' ','货币代码' =>'欧元','空显示' =>'',//**** 这个参数],.....
否则,如果小部件没有提供适当的属性,您可以使用匿名函数获取值
['属性' =>'你的属性','价值' =>功能($模型){如果( $model->your_attribute == NULL){return '对不起,所有 pr 都有 pitems';} 别的 {返回 $model->your_attribute;}},],Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty
The grid
echo DynaGrid::widget([
'columns' => $columns,
'showPersonalize' => true,
'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set
'options' => ['id' => 'assignsolic-grid'],
'gridOptions' => [
'options' => ['id' => 'grid'],
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showPageSummary'=>false,
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
'maxButtonCount' => 10,
],
'panel' => [
'type' => GridView::TYPE_PRIMARY,
// 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> </h3>',
'before'=>'<i>Select the Prs to assign solicitation and then click the Assign Solicitation button</i>',
'after' =>
Html::button(' <i class=" glyphicon glyphicon-road "></i> Assign Solicitation ', ['value' => Url::to('assignsolc'),'class' => 'btn btn-danger', 'id' => 'assignsolic']),
'footer' => false
],
'toolbar' => [
['content' => '{dynagridFilter}{dynagridSort}{dynagrid}'],
'{export}',
'{toggleData}'
],
'pjax' => true,
'bordered' => false,
'striped' => true,
'condensed' => true,
'responsive' => true,
'responsiveWrap' => false,
'containerOptions'=>['style'=>'overflow:scroll'],
]
]) ;
This returs an error of Setting unknown property: kartik\dynagrid\DynaGrid::emptyText how can i set the empty text
解决方案
You can define the value for null display directly in confi/main.php formatter component
'components' => [
.......
'formatter' => [
'class' => 'yii\i18n\Formatter',
'dateFormat' => 'dd.MM.yyyy',
'decimalSeparator' => ',',
'thousandSeparator' => ' ',
'currencyCode' => 'EUR',
'nullDisplay' => '', // **** this param
],
.....
Otherwise if the widget don't provide a proper attribute you can use an anonymous function for value
[
'attribute' => 'your_attribute',
'value' => function ($model) {
if ( $model->your_attribute == NULL) {
return 'Sorry all pr have pritems';
} else {
return $model->your_attribute;
}
},
],
这篇关于在 kartik dynagrid 中设置空文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!