contao-components/tablesort
contao-components/tablesort adds client-side table sorting to Contao projects. Easily enable sortable columns for HTML tables, improving data presentation and usability in the backend or frontend with minimal setup.
contao-components/tablesort package provides client-side sorting for HTML tables via Tablesort.js, a lightweight (~5KB) dependency. It fits well in LARAVEL/PHP applications where:
<script src="https://cdn.jsdelivr.net/npm/tablesort@latest/dist/tablesort.min.js"></script> and initialize via new Tablesort(document.querySelector('table')).wire:ignore).request()->query('sort') parameters).tl_content lists) with minimal adjustments.| Risk Area | Mitigation Strategy |
|---|---|
| Performance | Test with large tables (>10K rows); consider virtual scrolling or server-side sorting. |
| Data Consistency | Warn users that client-side sorting may not reflect backend state (e.g., database). |
| Contao-Specific Bugs | Verify compatibility with Contao’s table markup (e.g., nested <thead>, custom classes). |
| Dependency Bloat | Audit Tablesort.js for vulnerabilities (check Snyk or Libraries.io). |
| Accessibility | Ensure ARIA labels and keyboard navigation work (Tablesort.js may need custom config). |
<table class="tablesort">
<thead>
<tr><th>Name</th><th>Status</th></tr>
</thead>
<tbody>
@foreach($items as $item)
<tr><td>{{ $item->name }}</td><td>{{ $item->status }}</td></tr>
@endforeach
</tbody>
</table>
<script src="https://cdn.jsdelivr.net/npm/tablesort@latest/dist/tablesort.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
new Tablesort(document.querySelector('.tablesort'));
});
</script>
wire:ignore to prevent Livewire from touching the table.sort query param to Laravel routes (e.g., /api/items?sort=name).| Component | Compatibility Notes |
|---|---|
| Laravel Blade | ✅ Full support; add script tag or bundle via Mix. |
| Livewire | ⚠️ Use wire:ignore; initialize Tablesort in mounted() or Alpine.js. |
| Inertia.js | ✅ Works in Vue/React components; initialize after mount. |
| Tailwind/CSS | ✅ No conflicts; Tablesort adds minimal styles (can be overridden). |
| Contao CMS | ✅ Likely compatible; test with Contao’s table markup (e.g., tl_* tables). |
| Purifier/HTML | ⚠️ If using Laravel’s HTML purifier, whitelist tablesort classes/attributes. |
tablesort class to target tables.sort params.// routes/web.php
Route::get('/items', [ItemController::class, 'index'])
->name('items.index');
// app/Http/Controllers/ItemController.php
public function index(Request $request) {
$sort = $request->query('sort', 'name');
return Item::orderBy($sort)->get();
}
package.json or use a CDN with a specific version.<thead>) may require custom Tablesort config.How can I help you explore Laravel packages today?