Skip to content

Commit

Permalink
Update type datagrid
Browse files Browse the repository at this point in the history
  • Loading branch information
shivendra-webkul committed Jul 19, 2024
1 parent 2d5ce91 commit 08caac2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
42 changes: 21 additions & 21 deletions packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Webkul\Admin\DataGrids\Setting;

use Webkul\UI\DataGrid\DataGrid;
use Illuminate\Support\Facades\DB;
use Webkul\DataGrid\DataGrid;
use Illuminate\Database\Query\Builder;

class TypeDataGrid extends DataGrid
{
/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
public function prepareQueryBuilder(): Builder
{
$queryBuilder = DB::table('lead_types')
->addSelect(
Expand All @@ -22,51 +21,52 @@ public function prepareQueryBuilder()

$this->addFilter('id', 'lead_types.id');

$this->setQueryBuilder($queryBuilder);
return $queryBuilder;
}

/**
* Add columns.
*
* @return void
*/
public function addColumns()
public function prepareColumns(): void
{
$this->addColumn([
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
'type' => 'string',
'sortable' => true,
'filterable' => true,
'sortable' => true,
]);

$this->addColumn([
'index' => 'name',
'label' => trans('admin::app.datagrid.name'),
'type' => 'string',
'sortable' => true,
'filterable' => true,
'sortable' => true,
]);
}

/**
* Prepare actions.
*
* @return void
*/
public function prepareActions()
public function prepareActions(): void
{
$this->addAction([
'title' => trans('ui::app.datagrid.edit'),
'icon' => 'icon-edit',
'title' => trans('admin::app.settings.roles.index.datagrid.edit'),
'method' => 'GET',
'route' => 'admin.settings.types.edit',
'icon' => 'pencil-icon',
'url' => function ($row) {
return route('admin.settings.types.edit', $row->id);
},
]);

$this->addAction([
'title' => trans('ui::app.datagrid.delete'),
'method' => 'DELETE',
'route' => 'admin.settings.types.delete',
'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'type']),
'icon' => 'trash-icon',
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.roles.index.datagrid.delete'),
'method' => 'DELETE',
'url' => function ($row) {
return route('admin.settings.types.delete', $row->id);
},
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Webkul\Admin\Http\Controllers\Setting;

use Illuminate\Support\Facades\Event;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
use Illuminate\Support\Facades\Validator;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Lead\Repositories\TypeRepository;
use Webkul\Admin\DataGrids\Setting\TypeDataGrid;

class TypeController extends Controller
{
Expand All @@ -20,13 +23,11 @@ public function __construct(protected TypeRepository $typeRepository)

/**
* Display a listing of the type.
*
* @return \Illuminate\View\View
*/
public function index()
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return app(\Webkul\Admin\DataGrids\Setting\TypeDataGrid::class)->toJson();
return datagrid(TypeDataGrid::class)->process();
}

return view('admin::settings.types.index');
Expand Down

0 comments on commit 08caac2

Please sign in to comment.