Skip to content

Commit

Permalink
show filter for creator
Browse files Browse the repository at this point in the history
  • Loading branch information
stokic committed Dec 12, 2023
1 parent 0ff41f4 commit deadff4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 43 additions & 1 deletion src/DataTables/LeadActivityDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
Expand All @@ -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 = $('<select class=\"form-control\"><option value=\"\">Alle</option></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('<option value=\"' + key + '\" selected=\"selected\">' + value + '</option>');
} else {
select.append('<option value=\"' + key + '\">' + value + '</option>');
}
} );
} );
}
");
}

protected function getColumns(): array
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/leadactivity/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('sales-management::layouts.app')

@section('content')
{!! $dataTable->table() !!}
{!! $dataTable->table([], true) !!}

@endsection

Expand Down

0 comments on commit deadff4

Please sign in to comment.