Comments (8)
That is not related to this package. You have to use Spatie Query Builder filters.
https://spatie.be/docs/laravel-query-builder/v5/features/filtering#content-scope-filters
Just create your range inputs and make a request to your controller with the filter:
const minPrice = ref()
const maxPrice = ref()
this.$inertia.get(route('your-table-controller-route'), {
'fields[products]': 'id,name,price',
'filter[price_range]': `${minPrice.value},${maxPrice.value}`,
})
from inertiajs-tables-laravel-query-builder.
class ProductIndexController
{
public function __invoke()
{
$products = QueryBuilder::for(Product::class)
->defaultSort('name')
->allowedSorts(['name', 'price'])
->allowedFilters(['name', 'price', AllowedFilter::scope('price_between')])
->paginate()
->withQueryString();
return Inertia::render('Products/Index', [
'products' => $products,
])->table(function (InertiaTable $table) {
$table
->defaultSort('name')
->column(key: 'name', searchable: true, sortable: true, canBeHidden: false)
->column(key: 'price', searchable: true, sortable: true)
->column(label: 'Actions');
}
}
class Product extends Model
{
public function scopePriceBetween(Builder $query, $minPrice, $maxPrice): Builder
{
return $query->whereBetween('price', [$minPrice, $maxPrice]);
}
}
<script setup>
import { Inertia } from '@inertiajs/inertia'
import { Table } from '@protonemedia/inertiajs-tables-laravel-query-builder'
import { ref } from 'vue'
defineProps({
products: Object,
})
const minPrice = ref()
const maxPrice = ref()
const filterByPriceRange = () => {
Inertia.get(route('your-product-index-route'), {
'filter[price_between]': `${minPrice.value},${maxPrice.value}`,
})
}
</script>
<template>
<div id="filters">
<label>Min price</label>
<input type="text" v-model="minPrice" />
<label>Max price</label>
<input type="text" v-model="maxPrice" />
<button type="button" @click="filterByPriceRange">Filter by price range</button>
</div>
<Table :resource="products" />
</template>
from inertiajs-tables-laravel-query-builder.
@darkons is there a way to integrate them nicely inside the filters dropdown in the table component ?
from inertiajs-tables-laravel-query-builder.
@darkons i didnt really get the method u talked about can you please give me more details for backend & frontend ^^thank u
from inertiajs-tables-laravel-query-builder.
@darkons thank you very much for explainiing the code works perfectly and it helped undrestood the process, the only thing is when i change the page ( in pagination table ) i lose the price filters , & when i input price between filters i lose old filters provided by table api, is there a way to merge them together ? ( im new to inertia )
from inertiajs-tables-laravel-query-builder.
You must rebuild the current URL query string
const filterByPriceRange = () => {
var queryParams = new URLSearchParams(window.location.search)
queryParams.set('filter[price_between]', `${minPrice.value},${maxPrice.value}`)
Inertia.get(route('your-product-index-route'), {
queryParams.toString(),
})
}
from inertiajs-tables-laravel-query-builder.
With a few modifications to write back the parameters to my model values (in your case minPrice and maxPrice refs) it worked also for my usecase.
However, it looks not very integrated. Is there a nice way to integrate such custom filter forms into the tables search interface that is rendered when I set the field to searchable?
from inertiajs-tables-laravel-query-builder.
@mbeckerle-xqueue please let me know if you managed to do that
from inertiajs-tables-laravel-query-builder.
Related Issues (20)
- Reset button not working when global search is in slots HOT 3
- Is selectFilter using wildcards? HOT 2
- Chrome global search doesn't seem to be holding its focus state HOT 1
- I there any way to selectFilter sort by if the value is numerical HOT 5
- Laravel Mix build requires imports to have .js extensions HOT 2
- Support for Bootstrap
- style HOT 2
- API Resource
- v2.1.0 error popper.js with Vite 3.1.3 HOT 1
- Request for Tailwind CSS Prefix Option
- [FEATURE]: Support for default scaffolding like jet stream should be provided. HOT 1
- -1 as perPage parameter creates invalid SQL queries
- Column option to sort null values last HOT 1
- Compatibility with Inertia.js v1 HOT 4
- Proper way to style the table? HOT 1
- Pagination: changing page submits two requests HOT 2
- ⚠️ Don't start using this package for new projects HOT 9
- Reset button not working when used in slots HOT 3
- How to call a function when loading or reloading the table ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inertiajs-tables-laravel-query-builder.