Working on datatables

This commit is contained in:
David Bomba 2019-07-25 14:51:00 +10:00
parent 7a6f9c993b
commit fd9c746c8d
4 changed files with 159 additions and 20 deletions

View File

@ -18,6 +18,7 @@ use App\Models\Invoice;
use App\Repositories\BaseRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
use Yajra\DataTables\Html\Builder;
/**
* Class InvoiceController
@ -29,16 +30,6 @@ class InvoiceController extends Controller
use MakesHash;
/**
* InvoiceController constructor.
*
*/
public function __construct()
{
}
/**
* Show the list of Invoices
*
@ -46,12 +37,38 @@ class InvoiceController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index(InvoiceFilters $filters)
public function index(InvoiceFilters $filters, Builder $builder)
{
// $invoices = Invoice::filter($filters);
if (request()->ajax()) {
return DataTables::of(Invoice::all())
->make(true);
}
$builder->addAction();
$builder->addCheckbox();
$html = $builder->columns([
['data' => 'checkbox', 'name' => 'checkbox', 'title' => '', 'searchable' => false, 'orderable' => false],
['data' => 'invoice_number', 'name' => 'invoice_number', 'title' => trans('texts.invoice_number'), 'visible'=> true],
// ['data' => 'full_name', 'name' => 'full_name', 'title' => trans('texts.contact'), 'visible'=> true],
// ['data' => 'email', 'name' => 'email', 'title' => trans('texts.email'), 'visible'=> true],
// ['data' => 'created_at', 'name' => 'created_at', 'title' => trans('texts.date_created'), 'visible'=> true],
// ['data' => 'last_login', 'name' => 'last_login', 'title' => trans('texts.last_login'), 'visible'=> true],
// ['data' => 'balance', 'name' => 'balance', 'title' => trans('texts.balance'), 'visible'=> true],
// ['data' => 'action', 'name' => 'action', 'title' => '', 'searchable' => false, 'orderable' => false],
]);
$builder->ajax([
'url' => route('client.invoices.index'),
'type' => 'GET',
'data' => 'function(d) { d.key = "value"; }',
]);
$data['html'] = $html;
return view('portal.default.invoices.index');
return view('portal.default.invoices.index', $data);
}

View File

@ -40,6 +40,7 @@
"superbalist/laravel-google-cloud-storage": "^2.2",
"webpatser/laravel-countries": "dev-master#75992ad",
"wildbit/postmark-php": "^2.6",
"yajra/laravel-datatables-html": "^4.0",
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {

116
config/datatables.php Normal file
View File

@ -0,0 +1,116 @@
<?php
return [
/*
* DataTables search options.
*/
'search' => [
/*
* Smart search will enclose search keyword with wildcard string "%keyword%".
* SQL: column LIKE "%keyword%"
*/
'smart' => true,
/*
* Multi-term search will explode search keyword using spaces resulting into multiple term search.
*/
'multi_term' => true,
/*
* Case insensitive will search the keyword in lower case format.
* SQL: LOWER(column) LIKE LOWER(keyword)
*/
'case_insensitive' => true,
/*
* Wild card will add "%" in between every characters of the keyword.
* SQL: column LIKE "%k%e%y%w%o%r%d%"
*/
'use_wildcards' => false,
],
/*
* DataTables internal index id response column name.
*/
'index_column' => 'DT_RowIndex',
/*
* List of available builders for DataTables.
* This is where you can register your custom dataTables builder.
*/
'engines' => [
'eloquent' => \Yajra\DataTables\EloquentDataTable::class,
'query' => \Yajra\DataTables\QueryDataTable::class,
'collection' => \Yajra\DataTables\CollectionDataTable::class,
'resource' => \Yajra\DataTables\ApiResourceDataTable::class,
],
/*
* DataTables accepted builder to engine mapping.
* This is where you can override which engine a builder should use
* Note, only change this if you know what you are doing!
*/
'builders' => [
//Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent',
//Illuminate\Database\Eloquent\Builder::class => 'eloquent',
//Illuminate\Database\Query\Builder::class => 'query',
//Illuminate\Support\Collection::class => 'collection',
],
/*
* Nulls last sql pattern for Posgresql & Oracle.
* For MySQL, use '-%s %s'
*/
'nulls_last_sql' => '%s %s NULLS LAST',
/*
* User friendly message to be displayed on user if error occurs.
* Possible values:
* null - The exception message will be used on error response.
* 'throw' - Throws a \Yajra\DataTables\Exceptions\Exception. Use your custom error handler if needed.
* 'custom message' - Any friendly message to be displayed to the user. You can also use translation key.
*/
'error' => env('DATATABLES_ERROR', null),
/*
* Default columns definition of dataTable utility functions.
*/
'columns' => [
/*
* List of columns hidden/removed on json response.
*/
'excess' => ['rn', 'row_num'],
/*
* List of columns to be escaped. If set to *, all columns are escape.
* Note: You can set the value to empty array to disable XSS protection.
*/
'escape' => '*',
/*
* List of columns that are allowed to display html content.
* Note: Adding columns to list will make us available to XSS attacks.
*/
'raw' => ['action'],
/*
* List of columns are are forbidden from being searched/sorted.
*/
'blacklist' => ['password', 'remember_token'],
/*
* List of columns that are only allowed fo search/sort.
* If set to *, all columns are allowed.
*/
'whitelist' => '*',
],
/*
* JsonResponse header and options config.
*/
'json' => [
'header' => [],
'options' => 0,
],
];

View File

@ -3,7 +3,6 @@
@section('header')
@parent
<link href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
@stop
@section('body')
@ -13,7 +12,13 @@
<div class="row">
<div class="col-lg-12">
<div class="animated fadeIn">
<div class="col-md-12 card">
{!! $html->table() !!}
</div>
</div>
</div>
</div>
@ -22,10 +27,10 @@
</body>
@endsection
@section('footer')
@parent
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script>
@stop
@parent
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript" defer></script>
<script src="//cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js" defer></script>
{!! $html->scripts() !!}
@endsection