Git Product home page Git Product logo

Comments (3)

donmbelembe avatar donmbelembe commented on July 17, 2024

show everything in this action

from inertiajs-tables-laravel-query-builder.

BKirev avatar BKirev commented on July 17, 2024

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.

DimaVIII avatar DimaVIII commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.