本文整理汇总了PHP中yii\grid\GridView类的典型用法代码示例。如果您正苦于以下问题:PHP GridView类的具体用法?PHP GridView怎么用?PHP GridView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GridView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
* @return bool|string
* @throws Exception
*/
public function run()
{
$model = $this->model;
if (!$model) {
return false;
}
if (!$model->hasMethod('getLog')) {
throw new Exception("Attach " . ChangeLogBehavior::className() . " behavior to " . $model::className());
}
/**
* @var ChangeLogBehavior $model
*/
$logProvider = $model->getLog();
$view = $this->header;
$view .= GridView::widget(['dataProvider' => $logProvider, 'columns' => ['log_time:datetime', 'prefix', ['attribute' => 'message', 'content' => function ($item) {
$messages = unserialize($item['message']);
if (is_array($messages)) {
$message = "";
foreach ($messages as $attr => $changes) {
$message .= $attr . ": " . $changes . "<br>";
}
return $message;
}
return $messages;
}]]]);
return $view;
}
示例2: init
/**
* Inits widget
*/
public function init()
{
parent::init();
$this->initVisible();
$this->initSortable();
//GridViewAsset::register($this->view);
}
示例3: run
public function run()
{
$confirm = Yii::t('yii', 'Are you sure you want to delete this item?');
$js = <<<JS
\$(".delete-button").click(function(){
var tr = this.closest('tr');
var url = \$(this).data('url');
if (confirm("{$confirm}")) {
\$.ajax({
method: "POST",
url: url,
success: function(data) {
if (data) {
tr.remove();
}
}
});
}
});
JS;
Yii::$app->view->registerJs($js);
return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
return Html::a("{$model->name}.{$model->type}", $model->getUrl());
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'delete-button', 'title' => Yii::t('yii', 'Delete'), 'data-url' => Url::to(['/attachments/file/delete', 'id' => $model->id])]);
}]]]]);
}
示例4: run
public function run(){
if($this->is_pjax){
Pjax::begin($this->pjaxOptions);
}
parent::run();
if($this->isShowForm) {
echo PageSize::widget([
'model' => $this->filterModel,
'attribute' => $this->attribute,
'options' => [
'data-pjax' => '0',
],
]);
}
if($this->is_pjax){
Pjax::end();
}
echo ModelCrud::widget([
'size' => $this->modalSize,
'updateUrl' => ($this->updateUrl)? $this->updateUrl : Url::to(['update']),
'createUrl' => ($this->createUrl)? $this->createUrl : Url::to(['create']),
'updateVerb' => 'post',
'viewUrl' => Url::to(['view']),
'viewVerb' => 'post',
'createVerb' => 'post',
'modelTitle' => $this->modelTitle,
'template' => '{view}{update}{create}',
'modelClass' => $this->dataProvider->query->modelClass
]);
}
示例5: init
public function init()
{
parent::init();
$this->emptyText = Html::t('templete', 'noData');
$this->summary = Html::t('templete', 'summary');
$this->getView()->registerCssFile('/css/listStyle.css');
}
示例6: renderPager
public function renderPager()
{
// /controller/action -> #!controller/action
$str = parent::renderPager();
$str = str_replace('href="/', 'href="#!', $str);
return $str;
}
示例7: init
public function init()
{
$this->showHeader = false;
$this->showFooter = false;
$this->layout = '{items}';
$this->columns = [['class' => 'yii\\grid\\DataColumn', 'format' => 'raw', 'value' => function ($post) {
foreach ($post->postDates as $postDate) {
if (!isset($first)) {
$first = $postDate->PostDate;
}
$last = $postDate->PostDate;
}
if ($first == $last) {
$value = $first;
} else {
$value = $first . ' — ' . $last;
}
if ($post->PostText) {
$value = $value . '<br />' . $post->PostText;
}
return $value;
}], ['format' => 'raw', 'value' => function ($post) {
return '<span class="js-past_vacation_delete grid_delete_icon" data-post-id="' . $post->PostID . '"><i class="fa fa-trash"></i></span>';
}]];
parent::init();
}
示例8: renderTableBody
/**
* @inheritdoc
* @return string the rendering result.
*/
public function renderTableBody()
{
if (!$this->showHeader) {
return parent::renderTableBody();
}
$models = array_values($this->dataProvider->getModels());
$keys = $this->dataProvider->getKeys();
$rows = [];
foreach ($models as $index => $model) {
$key = $keys[$index];
if ($this->beforeRow !== null) {
$row = call_user_func($this->beforeRow, $model, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
$rows[] = $this->renderTableRow($model, $key, $index);
if ($this->afterRow !== null) {
$row = call_user_func($this->afterRow, $model, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
}
if (empty($rows)) {
$colspan = count($this->columns);
return "\n<tr><td colspan=\"{$colspan}\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
} else {
return "\n" . implode("\n", $rows) . "\n</tbody>";
}
}
示例9: renderTableRow
public function renderTableRow($model, $key, $index)
{
if ($this->filterRow !== null && call_user_func($this->filterRow, $model, $key, $index, $this) === false) {
return '';
}
return parent::renderTableRow($model, $key, $index);
}
示例10: renderSection
public function renderSection($name)
{
if ($name == '{tools}') {
return $this->renderTools();
} else {
return parent::renderSection($name);
}
}
示例11: renderSection
/**
* @inheritdoc
*/
public function renderSection($name)
{
if (isset($this->pluginSections[$name])) {
return $this->pluginSections[$name]->run();
} else {
return parent::renderSection($name);
}
}
示例12: init
/**
* @inheritdoc
*/
public function init()
{
if (empty($this->columns)) {
$this->columns = $this->columns();
}
$this->columns = array_merge($this->columns, $this->actions());
parent::init();
}
示例13: run
public function run()
{
parent::run();
echo '</div>';
if (!$this->options['ajax']) {
$this->registerClientScripts();
DataTablesAsset::register($this->getView());
}
}
示例14: renderSection
/**
* @inheritdoc
*/
public function renderSection($name)
{
switch ($name) {
case '{button}':
return $this->button;
default:
return parent::renderSection($name);
}
}
示例15: renderSection
public function renderSection($name)
{
switch ($name) {
case '{bulkActions}':
return $this->renderBulkActions();
default:
return parent::renderSection($name);
}
}