emmanuel/livewire-datatable-bs4
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require emmanuel/livewire-datatable-bs4
php artisan vendor:publish --tag="livewire-datatable-bs4"
This publishes the Bootstrap 4 views for livewire-datatables under resources/views/vendor/livewire-datatable-bs4.
Basic Usage: Extend your Livewire datatable component with the new views:
use MedicOneSystems\LivewireDatatable\View\ViewFactory;
public function configureViewFactory()
{
return ViewFactory::new()
->withBootstrap4();
}
First Use Case: Replace the default datatable view in a component like this:
use MedicOneSystems\LivewireDatatable\View\ViewFactory;
class UserDatatable extends Datatable
{
public function configureViewFactory()
{
return ViewFactory::new()
->withBootstrap4()
->withColumns([
Column::make("ID", "id"),
Column::make("Name", "name"),
]);
}
}
Then render it in a Blade view:
<livewire:user-datatable />
View Customization: Override specific parts of the datatable (e.g., pagination, table headers) by publishing the views and modifying them:
php artisan vendor:publish --tag="livewire-datatable-bs4" --force
Then edit files in resources/views/vendor/livewire-datatable-bs4.
Column Styling: Use Bootstrap 4 classes directly in column definitions:
Column::make("Status", "status")
->sortable()
->searchable()
->addClass('text-center') // Bootstrap 4 class
->format(fn($value) => '<span class="badge ' . ($value === 'active' ? 'badge-success' : 'badge-danger') . '">' . $value . '</span>');
Integration with Jetstream/Jetstrap: If using Jetstrap, leverage its components for consistency:
<x-jetstrap::card>
<livewire:user-datatable />
</x-jetstrap::card>
Dynamic Column Rendering: Use Blade components for reusable column logic:
Column::make("Actions", "actions")
->format(fn($row) => view('components.datatable-actions', ['row' => $row])),
Theming: Override the default Bootstrap 4 CSS by extending the package’s styles:
/* resources/css/app.css */
@import 'vendor/livewire-datatable-bs4/css/datatable.css';
.livewire-datatable-bs4 {
--bs-primary: #your-color;
}
View Publishing Overwrite:
vendor:publish) will overwrite your customizations. Use --force cautiously.update instead of publish for incremental changes.Bootstrap 4 Dependency:
.table, .form-control) and override them in your CSS.Livewire Datatables Version Lock:
MedicOneSystems/livewire-datatables. Major version mismatches (e.g., v1 vs. v2) will break functionality.composer.json:
"mediconesystems/livewire-datatables": "^1.0"
JavaScript Conflicts:
@this or @entangle directives for dynamic elements.Pagination Styling:
.page-link) may not align perfectly with the package’s defaults.pagination.blade.php view or use a third-party pagination component.Inspect Rendered HTML: Use browser dev tools to verify classes/structure. Example:
@dump($this->datatable->html())
(Requires MedicOneSystems/livewire-datatables@dev for this method.)
Check Published Views: After publishing, verify files exist in:
resources/views/vendor/livewire-datatable-bs4/
Livewire Logs: Enable Livewire logging to debug component interactions:
LIVEWIRE_LOG_LEVEL=debug
Custom Views: Extend the package by creating a new view service provider:
// app/Providers/DatatableServiceProvider.php
use MedicOneSystems\LivewireDatatable\View\ViewFactory;
class DatatableServiceProvider extends ServiceProvider
{
public function register()
{
ViewFactory::macro('withCustomStyles', function () {
return $this->withView('custom-datatable');
});
}
}
Localization:
Override language files in resources/lang/vendor/livewire-datatable-bs4.
Headless Mode: For API-only use, disable views entirely:
public function configureViewFactory()
{
return ViewFactory::new()->withoutViews();
}
Server-Side Processing:
Combine with livewire-tables for large datasets:
use LivewireTables\Column\Column;
use LivewireTables\Views\ViewFactory;
public function configureViewFactory()
{
return ViewFactory::new()
->withBootstrap4()
->withColumns([
Column::make("ID", "id"),
]);
}
---
How can I help you explore Laravel packages today?