diff --git a/packages/Webkul/Admin/src/DataGrids/Activity/ActivityDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Activity/ActivityDataGrid.php index 9c5e76442..6a1571449 100644 --- a/packages/Webkul/Admin/src/DataGrids/Activity/ActivityDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Activity/ActivityDataGrid.php @@ -6,6 +6,8 @@ use Illuminate\Support\Facades\DB; use Webkul\Admin\Traits\ProvideDropdownOptions; use Webkul\DataGrid\DataGrid; +use Webkul\Lead\Repositories\LeadRepository; +use Webkul\User\Repositories\UserRepository; class ActivityDataGrid extends DataGrid { @@ -42,7 +44,7 @@ public function prepareQueryBuilder(): Builder $this->addFilter('title', 'activities.title'); $this->addFilter('schedule_from', 'activities.schedule_from'); $this->addFilter('created_by', 'users.name'); - $this->addFilter('created_by_id', 'activities.user_id'); + $this->addFilter('created_by_id', 'users.name'); $this->addFilter('created_at', 'activities.created_at'); $this->addFilter('lead_title', 'leads.title'); @@ -82,12 +84,20 @@ public function prepareColumns(): void ]); $this->addColumn([ - 'index' => 'created_by_id', - 'label' => trans('admin::app.activities.index.datagrid.created_by'), - 'type' => 'string', - 'searchable' => false, - 'sortable' => true, - 'filterable' => true, + 'index' => 'created_by_id', + 'label' => trans('admin::app.activities.index.datagrid.created_by'), + 'type' => 'string', + 'searchable' => false, + 'sortable' => true, + 'filterable' => true, + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => UserRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], 'closure' => function ($row) { $route = urldecode(route('admin.settings.users.index', ['id[eq]' => $row->created_by_id])); @@ -102,12 +112,20 @@ public function prepareColumns(): void ]); $this->addColumn([ - 'index' => 'lead_title', - 'label' => trans('admin::app.activities.index.datagrid.lead'), - 'type' => 'string', - 'searchable' => true, - 'filterable' => true, - 'sortable' => true, + 'index' => 'lead_title', + 'label' => trans('admin::app.activities.index.datagrid.lead'), + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'filterable' => true, + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => LeadRepository::class, + 'column' => [ + 'label' => 'title', + 'value' => 'title', + ], + ], 'closure' => function ($row) { if ($row->lead_title == null) { return "N/A"; diff --git a/packages/Webkul/Admin/src/DataGrids/Contact/PersonDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Contact/PersonDataGrid.php index 152f16d70..24a5ddaf3 100644 --- a/packages/Webkul/Admin/src/DataGrids/Contact/PersonDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Contact/PersonDataGrid.php @@ -113,8 +113,14 @@ public function prepareColumns(): void 'searchable' => true, 'filterable' => true, 'sortable' => true, - 'filterable_type' => 'dropdown', - 'filterable_options' => $this->organizationRepository->all(['name as label', 'name as value'])->toArray(), + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => OrganizationRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], ]); } diff --git a/packages/Webkul/Admin/src/DataGrids/Lead/LeadDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Lead/LeadDataGrid.php index c431e6e55..467a79505 100644 --- a/packages/Webkul/Admin/src/DataGrids/Lead/LeadDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Lead/LeadDataGrid.php @@ -85,8 +85,8 @@ public function prepareQueryBuilder(): Builder $this->addFilter('id', 'leads.id'); $this->addFilter('user', 'leads.user_id'); - $this->addFilter('sales_person', 'leads.user_id'); - $this->addFilter('lead_source_name', 'lead_sources.id'); + $this->addFilter('sales_person', 'users.name'); + $this->addFilter('lead_source_name', 'lead_sources.name'); $this->addFilter('person_name', 'persons.name'); $this->addFilter('type', 'lead_pipeline_stages.code'); $this->addFilter('stage', 'lead_pipeline_stages.id'); @@ -118,8 +118,14 @@ public function prepareColumns(): void 'searchable' => false, 'sortable' => true, 'filterable' => true, - 'filterable_type' => 'dropdown', - 'filterable_options' => $this->userRepository->all(['name as label', 'id as value'])->toArray(), + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => \Webkul\Contact\Repositories\PersonRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], ]); $this->addColumn([ @@ -137,8 +143,14 @@ public function prepareColumns(): void 'searchable' => false, 'sortable' => true, 'filterable' => true, - 'filterable_type' => 'dropdown', - 'filterable_options' => $this->sourceRepository->all(['name as label', 'id as value'])->toArray(), + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => SourceRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], ]); $this->addColumn([ @@ -150,12 +162,20 @@ public function prepareColumns(): void ]); $this->addColumn([ - 'index' => 'person_name', - 'label' => trans('admin::app.leads.index.datagrid.contact-person'), - 'type' => 'string', - 'searchable' => false, - 'sortable' => true, - 'filterable' => true, + 'index' => 'person_name', + 'label' => trans('admin::app.leads.index.datagrid.contact-person'), + 'type' => 'string', + 'searchable' => false, + 'sortable' => true, + 'filterable' => true, + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => \Webkul\Contact\Repositories\PersonRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], ]); $this->addColumn([ diff --git a/packages/Webkul/Admin/src/DataGrids/Quote/QuoteDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Quote/QuoteDataGrid.php index d0c2f3d98..131fa7c2c 100644 --- a/packages/Webkul/Admin/src/DataGrids/Quote/QuoteDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Quote/QuoteDataGrid.php @@ -39,7 +39,7 @@ public function prepareQueryBuilder(): Builder $this->addFilter('id', 'quotes.id'); $this->addFilter('user', 'quotes.user_id'); - $this->addFilter('sales_person', 'quotes.user_id'); + $this->addFilter('sales_person', 'users.name'); $this->addFilter('person_name', 'persons.name'); $this->addFilter('expired_at', 'quotes.expired_at'); $this->addFilter('created_at', 'quotes.created_at'); @@ -67,11 +67,19 @@ public function prepareColumns(): void ]); $this->addColumn([ - 'index' => 'sales_person', - 'label' => trans('admin::app.quotes.index.datagrid.sales-person'), - 'type' => 'string', - 'sortable' => true, - 'filterable' => true, + 'index' => 'sales_person', + 'label' => trans('admin::app.quotes.index.datagrid.sales-person'), + 'type' => 'string', + 'sortable' => true, + 'filterable' => true, + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => \Webkul\User\Repositories\UserRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], 'closure' => function ($row) { $route = urldecode(route('admin.settings.users.index', ['id[eq]' => $row->user_id])); @@ -82,21 +90,29 @@ public function prepareColumns(): void $this->addColumn([ 'index' => 'expired_quotes', 'label' => trans('admin::app.quotes.index.datagrid.expired-quotes'), - 'type' => 'string', + 'type' => 'date', 'searchable' => false, 'filterable' => true, ]); $this->addColumn([ - 'index' => 'person_name', - 'label' => trans('admin::app.quotes.index.datagrid.person'), - 'type' => 'string', - 'sortable' => true, - 'filterable' => true, + 'index' => 'person_name', + 'label' => trans('admin::app.quotes.index.datagrid.person'), + 'type' => 'string', + 'sortable' => true, + 'filterable' => true, + 'filterable_type' => 'searchable_dropdown', + 'filterable_options' => [ + 'repository' => \Webkul\Contact\Repositories\PersonRepository::class, + 'column' => [ + 'label' => 'name', + 'value' => 'name', + ], + ], 'closure' => function ($row) { $route = urldecode(route('admin.contacts.persons.index', ['id[eq]' => $row->person_id])); - return "".$row->person_name.""; + return "".$row->person_name.''; }, ]); diff --git a/packages/Webkul/Admin/src/Http/Controllers/DataGridController.php b/packages/Webkul/Admin/src/Http/Controllers/DataGridController.php new file mode 100644 index 000000000..9693f843c --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Controllers/DataGridController.php @@ -0,0 +1,42 @@ +validate(request(), [ + 'datagrid_id' => ['required'], + 'column' => ['required'], + 'search' => ['required', 'min:2'], + ]); + + /** + * Preparing the datagrid instance and only columns. + */ + $datagrid = app(Crypt::decryptString($params['datagrid_id'])); + $datagrid->prepareColumns(); + + /** + * Finding the first column from the collection. + */ + $column = collect($datagrid->getColumns())->map(fn ($column) => $column->toArray())->where('index', $params['column'])->firstOrFail(); + + /** + * Fetching on the basis of column options. + */ + return app($column['filterable_options']['repository']) + ->select([$column['filterable_options']['column']['label'].' as label', $column['filterable_options']['column']['value'].' as value']) + ->where($column['filterable_options']['column']['label'], 'LIKE', '%'.$params['search'].'%') + ->get(); + } +} diff --git a/packages/Webkul/Admin/src/Resources/views/components/datagrid/toolbar/filter.blade.php b/packages/Webkul/Admin/src/Resources/views/components/datagrid/toolbar/filter.blade.php index 2611db630..c423d2c73 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/datagrid/toolbar/filter.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/datagrid/toolbar/filter.blade.php @@ -591,6 +591,52 @@ class="icon-cross-large cursor-pointer text-lg text-white ltr:ml-1.5 rtl:mr-1.5" + +