This component is part of Zinq Prime and requires a valid license to use.
Zinq TableBuilder is a powerful tool designed to streamline the creation of tables from Eloquent Collections in Laravel and Livewire. With its intuitive API and minimal configuration, TableBuilder allows you to effortlessly display Eloquent models in a clean, responsive format. By leveraging <zinq:table>
, it ensures your tables are fully responsive, accessible, and seamlessly adapt to both light and dark modes.
To start using TableBuilder, you can use BuildsTables
trait in your Livewire component:
use Mattbit\Zinq\Utilities\BuildsTables;
class Payments extends Component
{
use BuildsTables;
...
}
Or you can simply inject TableBuilder
instance:
use Mattbit\Zinq\Builders\TableBuilder;
class Payments extends Component
{
public function render(TableBuilder $tableBuilder)
{
...
}
}
To build a table, you need to call tableFromCollection
method from BuildsTable
trait or fromCollection
method on the builder instance. The method accepts an Eloquent Collection.
ID | Status | Amount | Created at | Updated at |
---|---|---|---|---|
4
|
processing
|
4820
|
Jun 3, 0:35 AM
|
Jun 3, 1:19 AM
|
3
|
success
|
1500
|
Jun 1, 0:11 AM
|
Jun 1, 1:13 AM
|
2
|
failed
|
2000
|
May 29, 0:23 AM
|
May 29, 1:07 AM
|
1
|
success
|
1000
|
May 25, 0:06 AM
|
May 25, 1:01 AM
|
Table can be used a string, so you can simply echo it in your blade template:
<div>
{!! $table !!}
</div>
TableBuilder uses Illuminate\Support\Collection
proxy to access collection methods. You can use all methods available in the Collection class.
<div>
@if ($table->isEmpty())
<p>No payments found.</p>
@else
<p>There are @{{ $table->count() }} payments.</p>
{!! $table !!}
@endif
</div>
By default TableBuilder will display all columns from the model and will use the attribute name as a header.
TableBuilder supports hidden attributes, which will not be displayed in the table.
If you wish to hide given attribute without modifying the model, you can use hide
method.
Status | Amount | Created at |
---|---|---|
processing
|
4820
|
Jun 3, 0:35 AM
|
success
|
1500
|
Jun 1, 0:11 AM
|
failed
|
2000
|
May 29, 0:23 AM
|
success
|
1000
|
May 25, 0:06 AM
|
TableBuilder will use te Eloquent's getAttribute
method to display the value of the attribute. If you wish to change this behaviour for specific attribute, you can use override
method.
Status | Amount | Created at |
---|---|---|
processing
|
$4,820.00
|
Jun 3, 0:35 AM
|
success
|
$1,500.00
|
Jun 1, 0:11 AM
|
failed
|
$2,000.00
|
May 29, 0:23 AM
|
success
|
$1,000.00
|
May 25, 0:06 AM
|
TableBuilder formats each attribute to prepare a nice label representation for you. It uppercase first letter, replaces any underscores with whitespaces and even formats id to be present as ID. If you want to display a custom header for given attribute, you can use rename
method.
Status | Amount | Date |
---|---|---|
processing
|
$4,820.00
|
Jun 3, 0:35 AM
|
success
|
$1,500.00
|
Jun 1, 0:11 AM
|
failed
|
$2,000.00
|
May 29, 0:23 AM
|
success
|
$1,000.00
|
May 25, 0:06 AM
|
Sometimes you need to display additional information in the table, like information from the related models. To fit this scenario, TableBuilder has add
method to add a new column to the table.
Status | Amount | Date | Customer name |
---|---|---|---|
processing
|
$4,820.00
|
Jun 3, 0:35 AM
|
Candelario Rippin
|
success
|
$1,500.00
|
Jun 1, 0:11 AM
|
Sammy Cummerata
|
failed
|
$2,000.00
|
May 29, 0:23 AM
|
Ms. Vernie Brekke V
|
success
|
$1,000.00
|
May 25, 0:06 AM
|
Corrine Ledner
|
If you want to display a show button for each row, you can use link
method. It will create a new column with a link to the given route.
TableBuilder will format date attributes using format specified in the config/zinq.php
file. You can modify default date format by changing date_format
key in the config file.
Or you can use override
method to change the date format for specific attribute.
TableBuilder will display the columns in the order they are defined in the model. If you want to change the order of the columns, you can use order
method.
Now we can combine all the methods to create a nice table.
We’re constantly expanding the capabilities of Zinq, and some powerful TableBuilder new features are scheduled for release in early 2025:
By purchasing a Zinq license today, you’ll secure lifetime access to all updates, ensuring you can take advantage of these features the moment they’re ready. Don’t miss this opportunity to lock in the promotional pricing now and guarantee your access to the best Zinq has to offer!