Updated 4 August 2022
Here we are going to discuss how to implement multiple Datagrid in Bagisto. I am assuming that you are already familiar with the default Datagrid creation. If not then you can check it from here,
https://devdocs.bagisto.com/1.x/advanced/datagrid.html#datagrid
Here we are going to discuss implementing multiple Datagrid in Bagisto.
As the default datagrid will handle only a single request at a time which means filtration, sorting and many other operations will get conflicted when you try to implement the multiple datagrids. To overcome this we have provided a trait ProvideDataGridPlus
in the namespace Webkul\Ui\DataGrid\Traits
.
When you add this trait to your database, then you have access to the toJson()
method which provides the JSON format data from the collection. The whole idea behind this is to add the component in the view file and provide the data source which will hit the controller via. ajax and in the controller, this will hit the toJson()
method which will provide the JSON in response.
ProductDatagrid
class present in the Webkul\Admin\DataGrids
,
1 2 3 4 5 6 7 8 |
namespace Webkul\Admin\DataGrids; class ProductDataGrid extends DataGrid { ... } |
ProvideDataGridPlus
trait in the mentioned class,
1 2 3 4 5 6 7 8 9 10 11 12 |
namespace Webkul\Admin\DataGrids; use Webkul\Ui\DataGrid\Traits\ProvideDataGridPlus; class ProductDataGrid extends DataGrid { use ProvideDataGridPlus; ... } |
toJson()
method will be available in the datagrid instance which will provide data to the component.ProductController
in the namespace Webkul\Product\Http\Controllers, there is an index method, just use the
toJson().
123456789101112131415161718192021
use Webkul\Admin\DataGrids\ProductDataGrid; class ProductController extends Controller{ /** * Display a listing of the resource. * * @return \Illuminate\View\View */ public function index() { if (request()->ajax()) { return app(ProductDataGrid::class)->toJson(); } return view($this->_config['view']); } ...}
1 2 3 4 5 6 7 |
<div class="page-content"> ... <datagrid-plus src="{{ route('admin.catalog.products.index') }}"></datagrid-plus> ... </div> |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.