Comments (3)
show everything in this action
from inertiajs-tables-laravel-query-builder.
UserController
public function index()
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->where('name', 'LIKE', "%{$value}%")->orWhere('email', 'LIKE', "%{$value}%");
});
});
$users = QueryBuilder::for(User::class)
->defaultSort('name')
->allowedSorts(['name', 'email'])
->allowedFilters(['name', 'email', $globalSearch])
->paginate()
->withQueryString();
return Inertia::render('Admin/Users', [
'users' => $users,
])->table(function (InertiaTable $table) {
$table->addSearchRows([
'name' => 'Name',
'email' => 'Email address',
])->addColumns([
'email' => 'Email address',
]);
});
}
Users.vue
<template>
<admin-layout>
<Table
:filters="queryBuilderProps.filters"
:search="queryBuilderProps.search"
:columns="queryBuilderProps.columns"
:on-update="setQueryBuilder"
:meta="users"
>
<template #head>
<tr>
<th @click.prevent="sortBy('name')">Name</th>
<th v-show="showColumn('email')" @click.prevent="sortBy('email')">Email</th>
</tr>
</template>
<template #body>
<tr v-for="user in users.data" :key="user.id">
<td>{{ user.name }}</td>
<td v-show="showColumn('email')">{{ user.email }}</td>
</tr>
</template>
</Table>
</admin-layout>
</template>
<script>
import { InteractsWithQueryBuilder, Tailwind2 } from '@protonemedia/inertiajs-tables-laravel-query-builder';
import AdminLayout from '@/Pages/Admin/AdminLayout'
export default {
mixins: [InteractsWithQueryBuilder],
components: {
Table: Tailwind2.Table,
AdminLayout,
},
props: {
users: Object
}
};
</script>
from inertiajs-tables-laravel-query-builder.
It's a feature of Query builder. You can add commas to preform filter search.
The Demo script is bugged therefore.
Quick fix is just to implode the array back to a string if you don't need multiple search filters.
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$value = is_array($value) ? implode(",", $value) : $value;
$query
->where('name', 'LIKE', "%{$value}%")
->orWhere('id', 'LIKE', "%{$value}%")
->orWhere('tags', 'LIKE', "%{$value}%")
->orWhereHas('comments', fn($query) =>
$query->where('body', 'like', '%' . $value . '%') )
->orWhereHas('firiend', fn($query) =>
$query->where('name', 'like', '%' . $value . '%'))
;
});
from inertiajs-tables-laravel-query-builder.
Related Issues (20)
- Input search range ( example for price min & max) HOT 8
- 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.