MedicOneSystems / MedicOneSystems/livewire-datatables
Select Filter Chain
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I have more than one selection filter,
"Publisher" filter and "Campaign Type" filter.
if I have selected the "Publisher" filter, then the results for the select "Campaign Type" filter should be chained.
But, it doesn't work well. Have to refresh the page to get correct results on "Campaign Type" filter.
How to refresh property "Campaign Type" filter when triggered from selected "Publisher" filter ?
class DatatableOfObjectives extends LivewireDatatable
{
public $exportable = true;
public $export_name = '';
protected $listeners = [
'refreshDataTable' => 'refreshTable'
];
public function __construct()
{
$this->export_name = 'Data Objectives ' . date('YmdHis');
}
public function builder()
{
return MsObjectives::query();
}
public function columns()
{
return [
NumberColumn::name('id')
->label('ID')
->defaultSort('asc')
->sortBy('id')
->hide(),
Column::name('ms_publisher.name')
->filterOn('ms_publishers.name')
->filterable( $this->publishers->pluck('name') )
->label('Publisher'),
Column::name('ms_campaign_type.name')
->filterOn('ms_campaign_types.name')
->filterable( $this->campaign_types->pluck('name') )
->label('Campaign Type'),
Column::name('name')
->label('Name')
->filterable()
->searchable(),
Column::name('description')
->label('Description')
->filterable()
->searchable(),
DateColumn::name('created_at')
->label('Created at'),
Column::callback(['id', 'name'], function ($id, $name) {
$model = MsObjectives::find($id);
return view('livewire.panels.masters.objectives.manage', [
'id' => $id,
'code' => $model->hashid(),
'name' => $name,
]);
})
->label('manage')
->unsortable()
->excludeFromExport()
];
}
public function getPublishersProperty()
{
return MsPublishers::all();
}
public function getCampaignTypesProperty()
{
$session = Session::get('datatable_of_objectives_filter');
return MsCampaignTypes::select([
'ms_campaign_types.id',
'ms_campaign_types.name',
])
->leftjoin('ms_publishers', 'ms_publishers.id', '=', 'ms_campaign_types.ms_publisher_id')
->when( isset($session['select'][1]) && count($session['select'][1]) > 0, function($query) use ($session) {
$filter_publisher = $session['select'][1];
return $query->whereIn('ms_publishers.name', $filter_publisher);
})
->get();
}
public function refreshTable()
{
$this->refreshLivewireDatatable();
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DatatableOfObjectives::getCampaignTypesProperty and refreshTable, then inspect how the datatable stores selected filters and triggers Livewire updates. Reproduce the Publisher and Campaign Type selection sequence. Done means Campaign Type options update after Publisher changes without requiring a page refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- full-stack
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100