PHP code example of cryptodev4 / orchid-tables

1. Go to this page and download the library: Download cryptodev4/orchid-tables 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/ */

    

cryptodev4 / orchid-tables example snippets


use CryptoDev4\OrchidTables\Screen\TDChecklist;

class UserTable extends Table {
//...
    public function columns(): array
    {
        return [
            TDChecklist::make(),
            //...
            TD::make('id'),
        ];
    }
}

class UserTable extends Table {
//...
    public function commandBar(): array {
        return [
            ModalToggle::make("my modal")->modal('myModal'),
        ];
    }
    public function columns(): array {
        return [
            TD::Checklist::make()->checkboxSet('form','screen-modal-form-myModal'),
        ];
    }

class UserScreen extends Screen {
//...
    public function activateUsers(Request $request){
        Alert::message('Selected item count is still ' . count($request->get('checkbox', []) ) );
        $request->flash();
    }

html(string|callable $content): self

date(bool $withHumanReadable = true, string $format = null): self

num(int $decimals = 0,
        string $suffix = null,
        string $decimalSeparator = ',',
        string $thousandsSeparator = DataHelpers::NBSP): self

TD::make('size')->num(2,'m²')

limit(int $max = 100, string $end = '...')

keyValues(int $maxDepth = 3)

// article: { user: { id: 42, first: "John", last: "Doe", __toString:"John Doe" } }
TD::make('user')->link(function(User $user){return route('user.show',$user->id)}),
//<a href="/users/show/42">John Doe</a>

TD::make('user')->link('user.create',['last','first'])
//<a href="/users/show/42">Doe<br> John</a>


# config/orchid-tables.php
        'cell'   => Mixins\CellExportFormattableMixin::class,

\CryptoDev4\OrchidTables\Facades\OrchidTables::mixinTdExportFormattables();

TD::make('name')->exportRender(function(string $value, User $entry, int $rowNum){
    return Str::upper($value).' #'.$entry->id.' (row-'.$rowNum.')';
})

use CryptoDev4\OrchidTables\Exports\QuickExport;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;

class UsersTableScreen extends Screen
{

    public function commandBar(): array
    {
        return [
            Button::make('export')->method('export')->rawClick(),
        ];
    }

    public function export(){
        $query = User::filters()->defaultSort('id', 'desc');
        return (new QuickExport($query, UserTable::class))->download('userExport.xlsx');
    }
//...

use CryptoDev4\OrchidTables\Screen\TableAdvanced

class UserTable extends TableAdvanced
{

    public function rowClass(User $row)
    {
        return $row->active ? 'bg-success' : 'bg-danger';
    }

    public function rowLink(User $row)
    {
        return route('admin.users.show',$row);
    }
//...

# /config/orchid-tables.php
use CryptoDev4\OrchidTables\Mixins;

return [
    'mixins' => [
        'can'    => Mixins\CanMixin::class,
        'cell'   => Mixins\CellMixin::class,
        'layout' => Mixins\LayoutMixin::class,
    ],

    'date_format' => null,
];

shell
php artisan vendor:publish --tag="orchid-tables.config"