Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datagrid searchable dropdown. #1374

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions packages/Webkul/Admin/src/DataGrids/Activity/ActivityDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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]));

Expand All @@ -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 "<span class='text-gray-800 dark:text-gray-300'>N/A</span>";
Expand Down
10 changes: 8 additions & 2 deletions packages/Webkul/Admin/src/DataGrids/Contact/PersonDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
]);
}

Expand Down
44 changes: 32 additions & 12 deletions packages/Webkul/Admin/src/DataGrids/Lead/LeadDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand All @@ -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([
Expand Down
42 changes: 29 additions & 13 deletions packages/Webkul/Admin/src/DataGrids/Quote/QuoteDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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]));

Expand All @@ -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 "<a href='".$route."'>".$row->person_name."</a>";
return "<a href='".$route."'>".$row->person_name.'</a>';
},
]);

Expand Down
42 changes: 42 additions & 0 deletions packages/Webkul/Admin/src/Http/Controllers/DataGridController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Webkul\Admin\Http\Controllers;

use Illuminate\Support\Facades\Crypt;

class DataGridController extends Controller
{
/**
* Look up.
*/
public function lookUp()
{
/**
* Validation for parameters.
*/
$params = $this->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();
}
}
Loading
Loading