laravel-admin grid内置的view模板不能满足展示需求时我们可以自定义view模板。步骤如下:
定义view模版文件
<div class="box">
@if(isset($title)) <div class="box-header with-border">
<h3 class="box-title"> {{ $title }}</h3>
</div>
@endif
@if ( $grid->allowTools() || $grid->allowExport() || $grid->allowCreation() ) <div class="box-header with-border">
<div class="pull-right">
{!! $grid->renderExportButton() !!}
{!! $grid->renderCreateButton() !!} </div>
@if ( $grid->allowTools() ) <span>
{!! $grid->renderHeaderTools() !!} </span>
@endif </div>
@endif
{!! $grid->renderFilter() !!}
<!-- /.box-header --><div class="box-body table-responsive no-padding">
<style type="text/css">
table{ border-collapse:collapse; border:solid 1px #97a0b3; background-color: #fffbdb;} table td{ border:solid 1px #97a0b3; padding:1px; text-align: right} table th{ border:solid 1px #97a0b3; padding:1px; text-align: center} </style>
<table class="table table-hover">
<thead>
<tr>
<th>{{request()->get('product','all')}}</th> <!-- 全局变量,不用赋值 -->
<th></th>
<th colspan="5">Total</th>
<th colspan="5">Plat_1</th>
<th colspan="5">Plat_2</th>
</tr>
</thead>
<tbody>
<tr >
<td style="text-align: center">日期</td>
<td style="text-align: center">产品</td>
<td style="text-align: center">Total Click</td>
<td style="text-align: center">Total Install</td>
<td style="text-align: center">Plat_1 Click</td>
<td style="text-align: center">Plat_1 Install</td>
<td style="text-align: center">Plat_2 Click</td>
<td style="text-align: center">Plat_2 Install</td>
</tr>
@foreach($grid->rows() as $row) <tr {!! $row->getRowAttributes() !!}>
@foreach($grid->columnNames as $name) <td {!! $row->getColumnAttributes($name) !!}>
{!! $row->column($name) !!} </td>
@endforeach </tr>
@endforeach </tbody>
</table></div>
{!! $grid->renderFooter() !!} <div class="box-footer clearfix">
{!! $grid->paginator() !!} </div></div>
如上定义的view模板按钮、filter、分页等继承了grid内置功能,只有表格内容为自定义样式展示。
定义好的view模版文件我们保存为
resources/views/reports/report.blade.php
引用模版文件
我们在controller 可以如下引用自定义模板:
$grid = new Grid(new AdsReports);//reports为定义变量,在本例中没有使用$grid->setView('reports.report', ["reports"=>$grid->rows()]);
本文采摘于网络,不代表本站立场,转载联系作者并注明出处:https://www.5amiao.com/baike/1105.html