You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 27, 2024. It is now read-only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[](https://packagist.org/packages/protonemedia/inertiajs-tables-laravel-query-builder)
This package provides a *DataTables-like* experience for [Inertia.js](https://inertiajs.com/) with support for searching, filtering, sorting, toggling columns, and pagination. It generates URLs that can be consumed by Spatie's excellent [Laravel Query Builder](https://github.com/spatie/laravel-query-builder) package, with no additional logic needed. The components are styled with [Tailwind CSS 3.0](https://tailwindcss.com/), but it's fully customizable and you can bring your own components. The data refresh logic is based on Inertia's [Ping CRM demo](https://github.com/inertiajs/pingcrm).

## Launcher 🚀
Hey! We've built a Docker-based deployment tool to launch apps and sites fully containerized. You can find all features and the roadmap on our [website](https://uselauncher.com), and we are on [Twitter](https://twitter.com/uselauncher) as well!
## Support
## Sponsorship Support
We proudly support the community by developing Laravel packages and giving them away for free. Keeping track of issues and pull requests takes time, but we're happy to help! If this package saves you time or if you're relying on it professionally, please consider [supporting the maintenance and development](https://github.com/sponsors/pascalbaljet).
## Features
* Global search
* Auto-fill: auto generates `thead` and `tbody` with support for custom cells
* Global Search
* Search per field
* Filters
* Select filters
* Toggle columns
* Sort columns
* Pagination
Expand All
@@ -36,14 +33,6 @@ We proudly support the community by developing Laravel packages and giving them
* Convert Table.vue styling to proper Tailwind syntax
* Improve styling on really small screens
* Better documentation about customization and move to real renderless components
## Installation
You need to install both the server-side package as well as the client-side package. Note that this package is only compatible with Laravel 9, Vue 3.0 and requires the Tailwind Forms plugin.
Expand All
@@ -60,64 +49,86 @@ The package will automatically register the Service Provider which provides a `t
#### Search fields
With the `addSearch` method, you can specify which attributes are searchable. Search queries are passed to the URL query as a `filter`. This integrates seamlessly with the [filtering feature](https://spatie.be/docs/laravel-query-builder/v3/features/filtering) of the Laravel Query Builder package.
With the `searchInput` method, you can specify which attributes are searchable. Search queries are passed to the URL query as a `filter`. This integrates seamlessly with the [filtering feature](https://spatie.be/docs/laravel-query-builder/v5/features/filtering) of the Laravel Query Builder package.
You need to pass in the attribute and the label as arguments. With the `addSearchRows` method, you can add multiple attributes at once.
Though it's enough to just pass in the column key, you may specify a custom label and default value.
Filters are similar to search fields, but they use a `select` element instead of an `input` element. This way, you can present the user a pre-defined set of options. Under the hood, this uses the same filtering feature of the Laravel Query Builder package.
Select Filters are similar to search fields, but they use a `select` element instead of an `input` element. This way, you can present the user a pre-defined set of options. Under the hood, this uses the same filtering feature of the Laravel Query Builder package.
This method takes three arguments: the attribute, the label, and a key-value array with the options.
The `selectFilter` method requires two arguments: the key, and a key-value array with the options.
With the `addColumn` method, you can specify which columns you want to be toggleable. You need to pass in a key and label for each column. With the `addColumns` method, you can add multiple columns at once.
By default, the `selectFilter` will add a *no filter* option to the array. You may disable this, or specify a custom label for it.
The `addColumn` method has an optional third parameter to disable the column by default:
#### Columns
With the `column` method, you can specify which columns you want to be toggleable, sortable,and searchable. You need to pass in at least a key or label for each column.
The `searchable` option is a shortcut to the `searchInput` method. The example below will essentially call `$table->searchInput('name', 'User Name')`.
```
#### Disable global search
By default, global search is enabled. This query will be applied to the filters by the `global` attribute. If you don't want to use the global search, you can use the `disableGlobalSearch` method.
$table->withGlobalSearch('Search through the data...');
});
```
Expand DownExpand Up
@@ -191,76 +202,20 @@ module.exports = {
#### Table component
To use the `Table` component and all its related features, you need to add the `InteractsWithQueryBuilder` mixin to your component and add the `Tailwind2.Table` component to the `components` key.
To use the `Table` component and all its related features, all you need to do is import the `Table` component, pass the `$inertia` object and the `users` data to the component.
You can use the named `#head` slot to provide the table header and the named `#body` slot to provide the table body. You can use the `showColumn` method to determine if a column should be visible or not. You can use the `sortBy` method to set the column you want to sort by.
```vue
<script setup>
import { Table } from "@protonemedia/inertiajs-tables-laravel-query-builder";
import { InteractsWithQueryBuilder, Tailwind2 } from '@protonemedia/inertiajs-tables-laravel-query-builder';
export default {
mixins: [InteractsWithQueryBuilder],
components: {
Table: Tailwind2.Table
},
props: {
users: Object
}
};
</script>
```
#### Attributes and pagination
The `filters`, `search`, `columns`, and `on-update` attributes of the `Table` component are required, but the the `InteractsWithQueryBuilder` mixin magically provides the values for those attributes. You just have to specify them like the example template above.
When you pass a `meta` object to the table, it will automatically provide a pagination component.
You can override the default pagination translations with the `setTranslations` method of the base component. You can do this in your main JavaScript file:
```js
import { Components } from "@protonemedia/inertiajs-tables-laravel-query-builder";
Components.Pagination.setTranslations({
no_results_found: "No results found",
previous: "Previous",
next: "Next",
to: "to",
of: "of",
results: "results",
});
```
#### Table.vue slots
Expand All
@@ -270,6 +225,7 @@ The `Table.vue` has several slots that you can use to inject your own implementa
| --- | --- |
| tableFilter | The location of the button + dropdown to select filters. |
| tableGlobalSearch | The location of the input element that handles the global search. |
| tableReset | The location of the button that resets the table. |
| tableAddSearchRow | The location of the button + dropdown to add additional search rows. |
| tableColumns | The location of the button + dropdown to toggle columns. |
| tableSearchRows | The location of the input elements that handle the additional search rows. |
Expand All
@@ -287,70 +243,28 @@ Each slot is provided with props to interact with the parent `Table` component.
The templates and logic of the components are entirely separated. This way, you can create new templates while reusing the existing logic.
There are nine components that you can import and use as a mixin for your templates. For example, to write your own `TableGlobalSearch` component, you can import the base component and use its logic by adding it as a mixin.
```vue
<template>
<input
class="form-input"
placeholder="Custom Global Search Component..."
:value="value"
@input="onChange($event.target.value)"
/>
</template>
<script>
import { Components } from '@protonemedia/inertiajs-tables-laravel-query-builder';
export default {
mixins: [Components.TableGlobalSearch],
};
</script>
```
Available components:
* Components.ButtonWithDropdown
* Components.OnClickOutside
* Components.Pagination
* Components.Table
* Components.TableAddSearchRow
* Components.TableColumns
* Components.TableFilter
* Components.TableGlobalSearch
* Components.TableSearchRows
A good starting point would be to duplicate the `js/Tailwind2` folder into your app and start customizing the templates from there.
## Testing
You can run the PHP test suite with `composer`:
There's a huge Laravel Dusk E2E test-suite that can be found in the `app` directory. This is a Laravel + Inertia application.
```bash
composer test
```
You can run the JS test suite with either `npm` or `yarn`:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->filters = $this->filters->reject(function (Filter $filter) use ($key) {
return $filter->key === $key;
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.