shaungoh01/open-inertia-datatable-laravel

A simple Laravel 5/6/7/8 service provider for building datatable for inertiaJS.

dev-main 2022-01-17 02:00 UTC

This package is not auto-updated.

Last update: 2024-05-03 12:45:15 UTC


README

Installation

Installing via composer

composer require shaungoh01/open-inertia-datatable-laravel

Publishing VueJs table Component

php artisan vendor:publish --tag=datatable-vuejs

Instruction to use

There is 2 part, 1st is to build proper datatable query using datatable() in a query builder like:

$users = User::datatable()->paginate(50);

You should pass the result to front-end and the second part is to use the paginate result in front-end. We can start by imoprting the datatable that we publish earlier

import Datatable from '@/InertiaDatatable/Datatable.vue'

export default defineComponent({
    ...
    components: {
        Datatable,
    },
})

Make sure the datatable result is pass to front-end

props: {
    users:{
        type: Object
    },
},

Now we need to declare an array for header. This is so that we can easily show what column we want in the table

data(){
    return {
        headers:[
            {
                display:"Id",
                column:"id"
            },
            {
                display:"Email",
                column:"email"
            }
        ]
    }
},

After All of this, we can simply just use the datatable html tag by

<datatable :headers="headers" :pagination="users"></datatable>