PHP code example of mfrouh / datatable-livewire

1. Go to this page and download the library: Download mfrouh/datatable-livewire library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mfrouh / datatable-livewire example snippets


php artisan make:datatable user

php artisan make:datatable backend.user

php artisan make:datatable backend/user



namespace App\Http\Livewire\Datatables;

use MFrouh\DataTable\Datatables\Datatables;
use App\Models\User;

class User extends Datatables
{

     /**
     * add model
     */
    public $model = User::class;


    /**
     * query builder
     *
     */
    public function queryBuilder()
    {
        return $this->model::query();
    }


    /**
     * 'method_name or route()' => 'permission',
     *  ex  'create' => 'create post',
     *
     */
    public array $tablePermissions = [];

    /**
     * add columns in array
     *
     */
    public function columns(): array
    {
        return [];
    }


    /**
     * add actions in array
     *
     */
    public function actions(): array
    {
        return [];
    }
}

  public function actions(): array
  {
        return [
            Action::header()->events(['action'  => 'label']),
            Action::header()->urls(['action'  => 'label']),
            Action::action()->events(['action'  => 'label']),
            Action::action()->urls(['action' => 'label'])
        ];
  }

  public function columns(): array
    {
        return [
           TextColumn::name('name')->label('label')->sortable()->searchable(),
           NumberColumn::name('name')->label('label')->sortable()->searchable(),
           MinuteColumn::name('name')->label('label')->sortable()->searchable(),
           PercentageColumn::name('name')->label('label')->sortable()->searchable(),
           LangColumn::name('name')->filename('filename')->label('label'),
           DateTimeColumn::name('name')->format(format')->label('label')->sortable()->searchable(),
        ];
    }