Download the PHP package clickbar/ag-grid-laravel without Composer
On this page you can find all versions of the php package clickbar/ag-grid-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download clickbar/ag-grid-laravel
More information about clickbar/ag-grid-laravel
Files in clickbar/ag-grid-laravel
Package ag-grid-laravel
Short Description AG Grid server-side adapter for Laravel.
License MIT
Homepage https://github.com/clickbar/ag-grid-laravel
Informations about the package ag-grid-laravel
AG Grid server-side adapter for Laravel
This package implements a server-side adapter for AG Grid with support for filtering, sorting, exporting and server-side selection.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
Querying a resource
Simply accept an AgGridGetRowsRequest
in your controller and return an instance of AgGridQueryBuilder
for the model that you want to query.
Filtering, sorting and exporting is handled automatically for you. You may also pass a JSON resource to the query builder to wrap your models with.
Set Filter Values
When using AG Grid with the serverSide
row model, you are responsible for providing the values for the set value filter (the frontend only knows a subset of the whole data and therefore cannot know all possible set values).
See the AgGridSetValuesRequest
class for the structure of the request.
IMPORTANT
You need to whitelist the columns the set filter values can be retrieved for. This can be done be providing an array with the columns/dotted relation:
If your model does not expose any relations or sensitive columns, you can also use ['*']
as wildcard.
Here's an example for the frontend implementation:
Server-side select
When using AG Grid with the serverSide
row model, you can't just pass the selected IDs to the server when performing a batch operation.
In this case, you may pass the current selection state of the grid to the server and resolve the selection there.
To do so, add the following to your request:
In your controller, use the AgGridQueryBuilder
to resolve the selection:
Exports
To enable server-side exports for your models, you must implement the AgGridExportable
interface.
After that, you can just pass exportFormat
as part of your request to the grid controller and the library handles transforming your models into Excel, CSV, or TSV files.
Custom Filters
Sometimes you may need to add custom filter scopes or other constraints to the query,
which are not covered by the standard AG Grid filters. In this case, you may populate the customFilters
object of the request with your own data.
On the backend side, your model must implement the AgGridCustomFilterable
interface as shown below:
Type definitions
You may use the following Typescript type definitions as a reference for implementing the requests on the frontend:
Frontend implementation
You are free to use any frontend technology or framework of your choice. However, here are some examples that you may use as a starting point four your own implementation
Creating a DataSource
In order to use the server-side row model, you must create a data source. Here is an exemplary implementation of such one:
Triggering a server-side export
Server-side exports are not implemented in AG Grid by default. However you can create a custom context menu or add a button somewhere that triggers the server-side export. The handler function may look something like this:
Tracking selection state
If you want to use server-side selects, you must track the current selection and filter state of the grid:
Limitations
- Only works with PostgreSQL as a storage backend due to some special SQL operators being used in set and json queries.
- Does not support multiple conditions per filter (AND, OR)
- Does not support server-side grouping for AG Grid's pivot mode
Filtering for values in relations is only supported one level deep. E.g you can filter forrelation.value
but notrelation.otherRelation.value
TODOs
- [ ] Implement set filter for nested json fields
- [ ] Implement multiple conditions per filter (
AND
,OR
) - [ ] Add type-safe data structures for selection and request data
- [ ] Test with mysql
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- clickbar. GmbH
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of ag-grid-laravel with dependencies
illuminate/contracts Version ^10.0
maatwebsite/excel Version ^3.1
spatie/laravel-package-tools Version ^1.14.0