У меня проблема при нажатии кнопки экспорта в Excel и печати кнопки с использованием таблиц данных в качестве службы, всегда показывая страницу не найдена и URL-адрес в браузере
http://localhost:4131/master/&draw=1&columns%5B0%5D%5Bdata%5D=r ..
Вот мой код:
App \ Datatables:
public function html()
{
return $this->builder()
->columns($this->setColumns())
->parameters($this->setParameters())
->ajax([
'type' => 'POST',
'data' => '{"_method":"GET","productIsActive":$("#productIsActive").val(),_token:window.Laravel.csrfToken}'
]);
}
protected function setParameters()
{
return [
'dom' => 'Bfrtip',
'buttons' => ['export', 'print', 'reset', 'reload'],
"rowCallback" => "function( row, data ) {
if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
$(row).addClass('selected');
if (productIsActive) $(row).addClass('warning');
else $(row).addClass('success');
}
if (! $(row).hasClass('row_clicked')) {
$(row).addClass('row_clicked');
}
}"];
}
App \ Html \ Controller:
namespace App\Http\Controllers\Masters;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Product;
use App\Category;
use App\Supplier;
use App\Http\Requests\ProductRequest;
use App\DataTables\Masters\ProductsDataTable;
class ProductsController extends Controller
{
private $data;
public function __construct()
{
$this->middleware('auth');
$this->data['productIsActive'] = true;
}
public function index(ProductsDataTable $dataTable)
{
$this->data['page_title'] = 'List All Products';
return $dataTable->render('masters.products.index', $this->data);
}
Ресурсы \ Просмотр:
@extends('masters.products.content')
@section('productBox')
{!! Form::hidden('productIsActive', $productIsActive, ['id' => 'productIsActive']) !!}
{!! $dataTable->table(['id'=>'products_table', 'class' => 'table table-bordered table-condensed'], true) !!}
@endsection
@push('partjs')
<link rel="stylesheet" href="{{ asset('vendor/datatables/datatables.min.css') }}"> <!-- datatables builder css 1.10.13-->
<script src="{{ asset('vendor/datatables/datatables.min.js') }}"></script> <!-- datatables builder js 1.10.13-->
<script src="{{ asset('vendor/datatables/buttons.server-side.js') }}"></script>
{!! $dataTable->scripts() !!}
@endpush
Route \ web:
Route::group(['prefix' => '/master', 'as' =>'master.','middleware' => ['auth']], function () {
Route::resource('/products', 'Masters\ProductsController');
Route::resource('/categories', 'Masters\CategoriesController');
Route::resource('/suppliers', 'Masters\SuppliersController');
});
Config \ app:
'providers' => [
..
Yajra\Datatables\DatatablesServiceProvider::class,
Yajra\Datatables\ButtonsServiceProvider::class,
..
Я решаю эту проблему после добавления ‘?’ в URL от AJAX
public function html()
{
return $this->builder()
->columns($this->setColumns())
->parameters($this->setParameters())
->ajax([
'url' => \Request::url().'?',
'type' => 'POST',
'data' => '{"_method":"GET","productIsActive":$("#productIsActive").val(),_token:window.Laravel.csrfToken}'
]);
}
Задача ещё не решена.
Других решений пока нет …