PHP code example of joe.szeto / tablelite

1. Go to this page and download the library: Download joe.szeto/tablelite 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/ */

    

joe.szeto / tablelite example snippets


\Tablelite\TablesliteServiceProvider::class

use Tablelite\Table as TableAlias;

class SomeComponent extends Component  {
    use \Tablelite\InteractsWithTablelite;
    
    public function table( TableAlias $table ){
        $table->schema([
            TextColumn::make('id'),
            TextColumn::make('name'),
        ])->records([
            [ 'id' => 1, 'name' => 'John'],
            [ 'id' => 2, 'name' => 'Doe'],
        ]);
    }
}

$table->keyBy('some_key');

$table->selectable();

$table->selectable(false);

$table->selectableRecord(fn($record) => $record->slug === 'foo');

$table->schema(fn(ColumnBuilder $builder) => [
    $builder->text('code')->searchable(),
]);

->records(
    fn($keyword) => // do something with this keyword
)

$table->schema(fn(ColumnBuilder $builder) => [
    $builder->text('code')->sortable(),
]);

->records(
    fn($sort) => // do something with this keyword
)

 $table->schema([
    TextColumn::make('id'),
    TextColumn::make('name'),
])
    ->records([
        ['id' => 1, 'name' => 'John'],
        ['id' => 2, 'name' => 'Doe'],
    ])->actions(fn(ActionFactory $actionFactory) => [
        $actionFactory->make('some_action')
            ->label('Action Label')
            ->action(function ($record) {
                // do something here
             })
    ]);


$actionFactory->make('some_action')->text()

$actionFactory->detail('some_action')->url()

$action->disabled()
// or
$action->disabled(function($record) : bool {} )

 ->headerActions(fn(ActionFactory $actionFactory) => [
    $actionFactory->make('assign')
        ->label('Assign Coupon')
        ->slideover('some-livewire-component', [
            // params for the livewire component...
        ])
])

$this->onSlideOver(
    'someMethod',
    loading: true,
    loadingPattern: 'cccb|accc'
)

$table->schema([
    TextColumn::make('id'),
    TextColumn::make('name'),
])
    ->records(
        function ($page) {
            // fetch api here
        }
    )
    ->paginateUsing(
        function ($records, PaginatorBuilder $builder) {
            // records is the response of the fetching
            return $builder
                ->items($records['data']) // the items
                ->total($records['total']) // total items
                ->perPage($records['per_page'])
                ->currentPage($records['current_page']);
        }
    );

composer 
app.php
bladehtml

<div>
    {{ $this->getTable() }}
</div>