1. Go to this page and download the library: Download inengine/tableui 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/ */
inengine / tableui example snippets
use App\Models\User;
use InEngine\TableUI\Table;
$table = Table::fromCollection(User::query()->latest()->limit(50)->get());
use InEngine\TableUI\Columns;
use InEngine\TableUI\ColumnTypes\Primitives\TextColumn;
use InEngine\TableUI\Options;
use InEngine\TableUI\Table;
$table = Table::fromCollection(
$messages,
new Columns([
new TextColumn('hid'),
new TextColumn('subject'),
]),
new Options(
defaultSortColumn: 'hid',
defaultSortDirection: 'desc',
actionIdKey: 'id', // selection keys + `{id}` in action URLs
perPage: 25,
),
);
use InEngine\TableUI\Actions;
use InEngine\TableUI\ActionTypes\ActionResponse;
use InEngine\TableUI\ActionTypes\DeleteAction;
use InEngine\TableUI\ActionTypes\UpdateAction;
use InEngine\TableUI\ActionTypes\ViewAction;
use InEngine\TableUI\Options;
use InEngine\TableUI\Table;
$table = Table::fromCollection(
$messages,
columns: null,
options: new Options(actionIdKey: 'id'),
actions: new Actions([
new ViewAction('Open', '/messages/{id}', bulk: false, isButton: true),
new UpdateAction(
'Mark unread',
static function (array $row): ActionResponse {
// Persist your domain change, then tell the table how to refresh rows:
return ActionResponse::patchRowsForRows([$row], ['has_been_read' => false]);
},
bulk: false,
isButton: true,
),
new DeleteAction(
'Delete',
static function (array $row): ActionResponse {
// Delete the model, then remove it from the Livewire row set:
return ActionResponse::removeRowsForRows([$row]);
},
bulk: false,
isButton: true,
),
// Bulk actions: Closure receives list<array> $rows
new DeleteAction(
'Delete selected',
static function (array $rows): ActionResponse {
return ActionResponse::removeRowsForRows($rows);
},
bulk: true,
isButton: true,
),
]),
);
use InEngine\TableUI\Options;
use InEngine\TableUI\Support\RowEmphasis;
new Options(
rowEmphasis: static fn (array $row): ?RowEmphasis => empty($row['has_been_read'])
? RowEmphasis::Bold
: null,
);
namespace App\TableUI\Columns;
use InEngine\TableUI\ColumnTypes\Column;
use InEngine\TableUI\Contracts\BuildsColumnFromAttributeKey;
use InEngine\TableUI\Contracts\DefinesColumnRenderers;
use InEngine\TableUI\Contracts\ParticipatesInColumnInference;
use InEngine\TableUI\Rendering\ColumnRendererInterface;
final class SkuColumn extends Column implements BuildsColumnFromAttributeKey, DefinesColumnRenderers, ParticipatesInColumnInference
{
public static function fromAttributeKey(string $attributeKey): Column
{
return new self($attributeKey);
}
public static function matchesSample(string $attributeKey, mixed $sample): bool
{
return str_contains(strtolower($attributeKey), 'sku');
}
/**
* @return list<class-string<ColumnRendererInterface>>
*/
public static function rendererClassNames(): array
{
return [SkuColumnRenderer::class];
}
/**
* @return class-string<ColumnRendererInterface>
*/
public static function defaultRendererClassName(): string
{
return SkuColumnRenderer::class;
}
}
namespace App\TableUI\Actions;
use InEngine\TableUI\ActionTypes\Action;
use InEngine\TableUI\ActionTypes\UpdateAction;
use InEngine\TableUI\Contracts\BuildsDefaultTableAction;
use InEngine\TableUI\Table;
final class ArchiveActionProvider implements BuildsDefaultTableAction
{
public static function forTable(Table $table): ?Action
{
return new UpdateAction(label: 'Archive', target: '/users/{id}/archive');
}
}
namespace App\TableUI\Filters;
use App\TableUI\Columns\SkuColumn;
use InEngine\TableUI\ColumnTypes\Column;
use InEngine\TableUI\Contracts\BuildsFilterDefinitionForColumn;
use InEngine\TableUI\FilterTypes\FilterDefinition;
use InEngine\TableUI\FilterTypes\FilterType;
final class SkuFilterDefinitionProvider implements BuildsFilterDefinitionForColumn
{
public static function forColumn(Column $column, ?array $enumOptions = null): ?FilterDefinition
{
if (! $column instanceof SkuColumn) {
return null;
}
return new FilterDefinition(
columnKey: $column->key(),
label: 'SKU',
type: FilterType::Text,
);
}
}