0

我想在 Yajra 中添加按钮,所以我阅读了http://dt54.yajrabox.com/buttons/eloquent。我跟着这一步。但仍然显示空白。

注意。如果我没有使用运行良好的数据表服务。

数据表类

命名空间 App\DataTables;

use App\employee;
use Yajra\Datatables\Services\DataTable;
class EmployeeDataTable extends DataTable
{

public function ajax()
{
return $this->datatables
->eloquent($this->query())
->make(true);
}

public function query()
{
    $query = employee::select();

    return $this->applyScopes($query);
}

public function html()
{
   return $this->builder()
                ->columns($this->getColumns())
                ->ajax('{{ url("Employee/index3") }}')
                ->parameters([
                    'dom'          => 'Bfrtip',
                    'buttons'      => ['export', 'print', 'reset', 'reload'],

                ]);
}

protected function filename()
{
    return 'employeedatatables_' . time();
}

在控制器中

use Yajra\Datatables\Facades\Datatables;
use App\DataTables\EmployeeDataTable;

public function index3(EmployeeDataTable $dataTable)
{
    return $dataTable->render('employee.users');
}

在视图中

@extends('layouts.app')

@section('content') 
<div class="col-md-8 col-md-offset-2">
<h3>test</h3>   

{!! $dataTable->table() !!}
</div>
{!! $dataTable->scripts() !!}
@endsection

如果我使用萤火虫,我有错误 304 未修改。你能告诉我我的错误吗?

4

1 回答 1

0

解决了..也许可以帮助某人..这是列搜索,并使用 Datatabale 服务添加操作

在数据表类中

public function ajax()
{

    return $this->datatables

        ->eloquent($this->query())
        ->addColumn('action', function ($query) {
                        return '<a href="#edit-'.$query->ID.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a> 
                    <a href="#delete-'.$query->ID.'" class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-minus-sign"></i> Del</a>';
                    })
         ->make(true);
}

public function query()
{
    $query = employee::select('ID','cNip','vName','vBankbranch');

    return $this->applyScopes($query);
}

public function html()
{
   return $this->builder()
                ->columns($this->getColumns())
                ->addAction(['width' => '10%'])
                ->ajax('')
                 ->parameters([
                    'dom'          => 'Bfrtip',
                    'buttons'      => ['export', 'print', 'reset', 'reload'],
                    'initComplete' => "function () {
                        this.api().columns().every(function () {
                            var column = this;
                            var input = document.createElement(\"input\");
                            $(input).appendTo($(column.footer()).empty())
                            .on('change', function () {
                                column.search($(this).val(), false, false, true).draw();
                            });
                        });
                    }",
                ]);
}

在视图中

@extends('layouts.app')
@section('content') 
<div class="col-md-8 col-md-offset-2">
<h3>test</h3>   
{!! $dataTable->table([], true) !!}
</div>
@endsection
@section('scripts')
{!! $dataTable->scripts() !!}
@endsection
于 2017-06-05T07:10:23.643 回答