diff --git a/src/DataTables/LeadActivityDataTable.php b/src/DataTables/LeadActivityDataTable.php index d606fb4..d383f26 100644 --- a/src/DataTables/LeadActivityDataTable.php +++ b/src/DataTables/LeadActivityDataTable.php @@ -23,6 +23,7 @@ public function dataTable(QueryBuilder $query): EloquentDataTable { return (new EloquentDataTable($query)) ->filter(function ($query) { + if(auth()->user()->hasRole('admin')) return; $query->where('created_by', auth()->id()); }, true) ->editColumn('is_done', function (LeadActivity $leadActivity) { @@ -82,6 +83,10 @@ public function query(LeadActivity $model): QueryBuilder */ public function html(): HtmlBuilder { + //select distinct created_by user + $users = LeadActivity::select('created_by')->distinct()->get()->pluck('user.full_name', 'created_by')->toArray(); + $users = json_encode($users); + return $this->builder() ->dom('lfrtip') ->setTableId('deal-table') @@ -90,7 +95,44 @@ public function html(): HtmlBuilder ->addTableClass('table-striped') ->pageLength(25) ->orderBy(8, 'asc') // Set default order by 'start_date' asc - ->language("https://cdn.datatables.net/plug-ins/1.13.1/i18n/de-DE.json"); + ->language("https://cdn.datatables.net/plug-ins/1.13.1/i18n/de-DE.json") + ->initComplete(" + + function (settings, json) { + + this.api().columns([2]).every( function () { + var column = this; + // Use column title as label for select + var title = $(column.header()).text(); + + // Generate select + var select = $('').appendTo( $(column.footer()).empty() ) + // Search when selection is changed + .on( 'change', function () { + var val = $(this).val(); + column.search( this.value ).draw(); + } ); + // Capture the data from the JSON to populate the select boxes with all the options + var extraData = (function(i) { + + switch(i) { + case 2: + return $users; + } + })(column.index()); + + + // Draw select options + Object.entries(extraData).forEach( ([key, value]) => { + if(column.search() === key){ + select.append(''); + } else { + select.append(''); + } + } ); + } ); + } + "); } protected function getColumns(): array diff --git a/src/resources/views/leadactivity/index.blade.php b/src/resources/views/leadactivity/index.blade.php index c9c2e00..97526fc 100644 --- a/src/resources/views/leadactivity/index.blade.php +++ b/src/resources/views/leadactivity/index.blade.php @@ -1,7 +1,7 @@ @extends('sales-management::layouts.app') @section('content') - {!! $dataTable->table() !!} + {!! $dataTable->table([], true) !!} @endsection