PHP code example of team-nifty-gmbh / tall-datatables

1. Go to this page and download the library: Download team-nifty-gmbh/tall-datatables 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/ */

    

team-nifty-gmbh / tall-datatables example snippets


public array $enabledCols = [
    'id',
    'name',
    'email',
    'email_verified_at',
    'created_at',
    'updated_at',
];

public function getLayout(): string
{
    return 'tall-datatables::layouts.grid';
}

protected string $view = 'data-tables.my-custom-view';

use TeamNiftyGmbH\DataTable\Htmlables\DataTableButton;

...

public function getTableActions(): array
{
    return [
        DataTableButton::make()
            ->label('Create')
            ->icon('plus')
            ->color('primary')
            ->attributes([
                'x-on:click' => '$dispatch(\'create-user\')',
            ]),
    ];
}

use TeamNiftyGmbH\DataTable\Htmlables\DataTableButton;

...

public function getRowActions(): array
{
    return [
        \TeamNiftyGmbH\DataTable\Htmlables\DataTableButton::make()
            ->label('Edit')
            ->icon('eye')
            ->color('primary')
            ->attributes([
                'x-on:click' => '$wire.edit(record.id)',
                'x-bind:class' => 'record.is_locked ? \'hidden\' : \'\''
            ]),
        \TeamNiftyGmbH\DataTable\Htmlables\DataTableButton::make()
            ->label('Delete')
            ->icon('trash')
            ->color('negative'),
    ];
}

> DataTableButton::make()
>    ->label('Edit')
>    ->icon('pencil')
>    ->color('primary')
>    ->attributes([
>        'x-on:click' => '$wire.edit(record.id); $event.stopPropagation()', // <--- here
>      ]),

## Combining Columns

You can combine multiple columns into one by overwrite the get{Position}Appends.
As the name states the defined columns will be appended to the position.


protected function getBuilder(Builder $builder): Builder
{
    return $builder->with('roles');
}

protected function getReturnKeys(): array
{
    return array_merge(parent::getReturnKeys(), ['currency.iso']);
}

Route::get('/users', \App\Http\Livewire\DataTables\UserDataTable::class);

public function getUrl(): string
{
    return route('users.show', $this->id);
}

use TeamNiftyGmbH\DataTable\Traits\BroadcastsEvents;

class User extends Authenticatable
{
    use BroadcastsEvents;
}

Broadcast::channel(App\Models\User::class, function ($user, $id) {
    return $user->id === (int) $id;
});

Broadcast::channel(\App\Models\User::getBroadcastChannel(), function ($user) {
    return true;
});

use TeamNifty\TallDatatables\Traits\HasFrontendAttributes;

class User extends Authenticatable
{
    use HasFrontendAttributes;
    
    protected string $detailRouteName = 'users.id';
    ...
}

public function getDetailRouteParameters(): array
{
    return [
        'id' => $this->id,
        'foo' => 'bar',
    ];
}

$user = User::first();
$user->href; // returns the detail route for the user

use TeamNiftyGmbH\DataTable\Htmlables\DataTableRowAttributes;

...

public function getRowAttributes(): array
{
    return DataTableRowAttributes::make()
        ->bind('class', 'record.is_active ? \'bg-green-100\' : \'bg-red-100\'')
        ->on('click', 'alert($event.detail.record.id)')
        ->class('cursor-pointer')
}

public bool $hasInfiniteScroll = true;

public bool $showFilterInputs = true;

public bool $hasHeader = false;

protected string $iconName = 'user';

use TeamNifty\TallDatatables\Contracts\InteractsWithDataTables;

class User extends Authenticatable implements InteractsWithDataTables
{
    ...
    
    public function getLabel(): string
    {
        return $this->name;
    }
    
    public function getDescription(): string
    {
        return $this->email;
    }
}

use TeamNifty\TallDatatables\Casts\Date;

public bool $isSearchable = false;
js
module.exports = {
    presets: [
        ...
        m-nifty-gmbh/tall-datatables/resources/views/**/*.blade.php',
        './vendor/team-nifty-gmbh/tall-datatables/resources/js/**/*.js',
    ],
    ...
}
bash
php artisan vendor:publish --tag="tall-datatables-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="tall-datatables-config"
bash
php artisan vendor:publish --tag="tall-datatables-views"