Giter VIP home page Giter VIP logo

primevue-datatables's Introduction

Laravel + PrimeVue Datatables

Latest Version on Packagist Total Downloads GitHub Actions

This is a simple, clean and fluent serve-side implementation of PrimeVue Datatables in Laravel.

image

Features

  • Global Search including searching in relationships up to a depth of 3, e.g author.user.name
  • Per-Column filtering out of the box
  • Column Sorting with direction toggling
  • Pagination with a dynamic no. or records per page setting
  • Fully compatible with PrimeVue Datatable

Installation

You can install the package via composer:

composer require savannabits/primevue-datatables

Usage

Server Side

It is as simple as having this in your index() function of your controller:

public function index(Request $request): JsonResponse
{
    $list = PrimevueDatatables::of(Book::query())->make();
    return response()->json([
        'success' => true,
        'payload' => $list,
    ]);
}

Required Query Parameters

The server-side implementation uses two parameters from your laravel request object to perform filtering, sorting and pagination: You have to pass the following parameters as query params from the client:

  1. Searchable Columns (Passed as searchable_columns) - Used to specify the columns that will be used to perform the global datatable search
  2. Dt Params (Passed as dt_params) - This is the main Datatable event object as received from PrimeVue. See Lazy Datatable documentation for more details

Client Side:

Here is a gist of a Fully Working Vue3 + Tailwindcss component for the client side.
Go through PrimeVue's Lazy Datatable documentation for details on frontend implementation.

Here is an example of your loadLazyData() implementation:

const loadLazyData = async () => {
    loading.value = true;

    try {
        const res = await axios.get('/api/books',{
            params: {
                dt_params: JSON.stringify(lazyParams.value),
                searchable_columns: JSON.stringify(['title','author.name','price']),
            },
        });

        records.value = res.data.payload.data;
        totalRecords.value = res.data.payload.total;
        loading.value = false;
    } catch (e) {
        records.value = [];
        totalRecords.value = 0;
        loading.value = false;
    }
};

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

primevue-datatables's People

Contributors

coolsam726 avatar julian367 avatar kevinwheeler avatar lchris44 avatar str4wh4t avatar zamblas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

primevue-datatables's Issues

Per-Column filtering

In the readme it mentions Per-Column filtering out of the box, how can we apply it?

I'm using it like the example on primevue, but filterModel is undefined

image

Feature Request: Match casing and accent

Hi,
I would like to be able to enable or disable casing. In postgres this can be done easily changing from LIKE to ILIKE also I would like to ignore accents on searchs if that is possible.
Do you think you would be able to implement this or do you need some help?

support for sorting based on nested realtionships

hello , is there any plan or any guidance to add support to this package to sort based on nested realtions too ?
like
relation1.relation2.column
because currently it just supports 1 lvl of relation

Problem in sorting many to many relations

Hi. I get this error when trying to sort a column in my table which is loading from a many to many relationship.

Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsToMany::getOwnerKeyName()
/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php line 71

I tracked it and looks like method getOwnerKeyName() does not exist in belongsToMany relations
take a look at /vendor/savannabits/primevue-datatables/src/PrimevueDatatables.php:128

Need export function

i wonder is there any export all to csv function base on current filter available in this library?
if have how to use/call it?

Relationship with json column seems not to work when filtering and searching

Hi! Thanks for your work. I am trying to use json column with Laravel but I encountered some small issue with the json column relationships.

I have this set of data, notice the name is inside the json datatype column
image

User.php

public function country()
{
    return $this->belongsTo(Country::class);
}

Index.vue

const params = {
  params: {
    dt_params: JSON.stringify(lazyParams.value),
    searchable_columns: JSON.stringify(['name', 'email', 'country.data.name']),
  }
}

Unfortunately, it return this error when I load the datatable

Call to undefined relationship [data] on model [App\\Models\\Country].

Thanks.

[EXAMPLE] Per-Column filtering out of the box

Hello, I have been testing the implementation with the package.

But I have problems and I also don't know how to implement filtering by column, I don't know if anyone has any examples of integration.

Error on install

Laravel 10.15.0

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - savannabits/primevue-datatables[v0.1.0, v1.0.0, ..., v1.2.0] require illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
    - savannabits/primevue-datatables[v1.3.0, ..., v1.4.0] require illuminate/support ^8.0|^9.0 -> found illuminate/support[v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.10] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires savannabits/primevue-datatables * -> satisfiable by savannabits/primevue-datatables[v0.1.0, v1.0.0, ..., v1.4.0].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require savannabits/primevue-datatables:*" to figure out if any version is installable, or "composer require savannabits/primevue-datatables:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

how to pass parameters from laravel to this package

hi , i am trying to use this package for my prime vue front end . i am receiving the data like below :

{"global":{"value":"test","matchMode":"contains"},"name":{"value":"cis","matchMode":"contains"},"status":{"value":"123","matchMode":"equals"},"abbreviation":{"value":"","matchMode":"equals"},"services":{"value":"","matchMode":"contains"},"primary-pm":{"value":"","matchMode":"equals"},"primary-engineer":{"value":"","matchMode":"equals"}}

andd from url url :

{{baseUrl}}/customers?filters=%7B%22global%22:%7B%22value%22:%22test%22,%22matchMode%22:%22contains%22%7D,%22name%22:%7B%22value%22:%22cis%22,%22matchMode%22:%22contains%22%7D,%22status%22:%7B%22value%22:%22123%22,%22matchMode%22:%22equals%22%7D,%22abbreviation%22:%7B%22value%22:%22%22,%22matchMode%22:%22equals%22%7D,%22services%22:%7B%22value%22:%22%22,%22matchMode%22:%22contains%22%7D,%22primary-pm%22:%7B%22value%22:%22%22,%22matchMode%22:%22equals%22%7D,%22primary-engineer%22:%7B%22value%22:%22%22,%22matchMode%22:%22equals%22%7D%7D

and in my controller i have this :

 $list = PrimevueDatatables::of(Customer::query())->make();
        dd($list);

i want to know how should i pass the $request->get('filters') that i can use this package for filters . thanks in advance

Not able to filter $appends column

Hi,
in my models, i have this custom column which is not in database table ($appends = ['case_uid_prefix']), and it seem like this library not support filter appends column.
Any suggestion or a way to solve this issue?

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.