contao-components/tablesorter
Contao Tablesorter integrates the jQuery tablesorter plugin into Contao CMS, adding client-side sorting and related table enhancements for back end or front end listings. Useful for making tabular data easier to scan, sort, and navigate.
Installation
composer require contao-components/tablesorter
npm install tablesorter --save
Ensure jquery and tablesorter JS/CSS are included in your Laravel resources/js/app.js and resources/css/app.css.
Basic Blade Integration
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tbody>
<!-- Data rows -->
</tbody>
</table>
@push('scripts')
<script>
$(document).ready(function() {
$("#myTable").tablesorter();
});
</script>
@endpush
First Use Case Sort a static HTML table on a Laravel admin dashboard or user-facing grid.
Dynamic Table Data Use Laravel Blade directives to render tables from Eloquent collections:
@foreach($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->role }}</td>
<td>{{ $user->created_at->diffForHumans() }}</td>
</tr>
@endforeach
Resource Controller Integration
Pair with Laravel’s ResourceController for CRUD tables:
public function index()
{
$users = User::latest()->paginate(10);
return view('users.index', compact('users'));
}
Livewire/Alpine.js Hybrid Combine with Livewire for reactive sorting:
document.addEventListener('livewire:init', () => {
Livewire.on('tableSorted', () => {
$("#myTable").trigger("update"); // Refresh Livewire data
});
});
API-Driven Tables Fetch data via AJAX and update the table dynamically:
$.get('/api/users', function(data) {
let tbody = $('#myTable tbody');
tbody.empty();
data.forEach(user => {
tbody.append(`<tr><td>${user.name}</td><td>${user.role}</td></tr>`);
});
$("#myTable").trigger("update"); // Re-initialize Tablesorter
});
jQuery Dependency
jquery is loaded before tablesorter. Use Laravel Mix to auto-order scripts:
// webpack.mix.js
mix.js('resources/js/app.js', 'public/js')
.scripts([
'jquery.js',
'tablesorter.js'
]);
CSS Conflicts
.tablesorter thead tr th,
.tablesorter tbody tr td {
padding: 0.5rem;
text-align: left;
}
Dynamic Row Addition
$("#myTable").trigger("update");
Server-Side Sorting
orderBy with AJAX:
$.get('/api/users', { sort: 'name', order: 'desc' }, function(data) { ... });
Console Errors: Check for missing jQuery or incorrect initialization:
Uncaught TypeError: $(...).tablesorter is not a function
→ Verify tablesorter.js is included.
Sorting Not Working: Ensure <thead> exists and columns are explicitly defined:
<table class="tablesorter" data-sort-list="[[0,0],[1,1]]">
<!-- ... -->
</table>
Custom Widgets
Extend Tablesorter with Laravel widgets (e.g., TablesorterWidget):
class TablesorterWidget extends Widget
{
public function render()
{
$this->view->with('columns', $this->columns);
return view('widgets.tablesorter');
}
}
Service Provider
Register Tablesorter globally in AppServiceProvider:
public function boot()
{
View::composer('*', function ($view) {
$view->with('tablesorterScripts', '
<script>$(document).ready(function() { $(".tablesorter").tablesorter(); });</script>
');
});
}
Tailwind Integration Use arbitrary variants for styling:
<table class="w-full border-collapse [&_th]:border-b [&_td]:border-b">
<!-- ... -->
</table>
How can I help you explore Laravel packages today?