larapeak/inertiajs-data-tables

This is my package InertiajsDataTables

Fund package maintenance!
larapeak

Installs: 24

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Language:Vue

v0.1 2021-05-19 13:03 UTC

This package is auto-updated.

Last update: 2024-03-25 22:59:38 UTC


README

Larapeak

Create Data Tables in Laravel with Ease!

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a trait that will generate a datatable for your model. It also provides Vue components that you can use with Inertiajs.

Installation

You can install the package via composer:

composer require larapeak/inertiajs-data-tables

You can publish the Vue components with following command:

php artisan vendor:publish --provider="Larapeak\InertiajsDataTables\InertiajsDataTablesServiceProvider" --tag="assets"

The Vue components will be published in:

resources\js\Shared\DataTables

Usage

Your Eloquent models should use the Larapeak\InertiajsDataTables\HasSorting trait.

Here's an example of how to implement the trait:

namespace App\Models;

use Larapeak\InertiajsDataTables\HasSorting;
use Illuminate\Database\Eloquent\Model;

class YourEloquentModel extends Model
{
    use HasSorting;

    public $sortables = [
        'field1', 'field2', 'field3'
    ]
}

On your Vue page you can use the DataTable component like this:

<template>
    <data-table :tableData:"data" :tableFields="tablefields" :filters="filters" model="posts" slug></data-table>
</template>

<script>
    import DataTable from '@/Shared/DataTables/DataTable'
    
    export default {
        components: {
            DataTable,
        },
        
        props: {
            data: Array,
            filters: Object,
        },
        
        data() {
            return {
                tableFields: [
                    {
                        id: 'field1',
                        name: 'Field1',
                        type: 'text',
                    },
                    {
                        id: 'field2',
                        name: 'Field2',
                        type: 'text',
                    },
                    {
                        id: 'field3',
                        name: 'Field3',
                        type: 'text',
                    }
                ]
            }
        }
    }
</script>

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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