Logo Beartropy Tables

Beartropy Tables

Basic Usage
Learn how to create and use Beartropy Tables.
Creating a table

The artisan way

To create a table you can run the following:

1php artisan make:yatable MyBrandNewTable
2 
3# Or pre-fill columns from a model
4php artisan make:yatable MyBrandNewTable --model=User
Rendering the table

Rendering

This is nothing more than a livewire component, so the rendering is just the same:

Fullpage layout

Add the layout attribute right before the class with your layout:

1#[Layout('layouts.app')]
2class MyBrandNewTable extends YATBaseTable

Set layout in the component

You can also set the layout in the component:

1public function settings(): void {
2 $this->setLayout('layouts.app');
3}

Included in blade view

Simply use the livewire tag:

1<livewire:mybrandnewtable />
Base functions

Core Methods

The table component relies on a few core methods:

settings(): void
Here you can set some settings to the table in general: title, column id, bulk, state handler, etc.
You can also define the layout using $this->setLayout('layouts.app').

data(): collection
Here you return the data. As is, a collection of arrays or objects, you return it we display it. When you create a table an example of data is in the stub in order to see what is expected.

columns(): array
Here you return an array of column instances with the modifiers you want.

filters(): array
Here you return an array of filter instances.

options(): array
Here you return an array with function => label form. This will generate an "Options" button in the view that will display a dropdown with the options you set and they will call the function established as key.

1public function settings(): void {
2// Set general settings: title, column id, etc.
3}
4 
5public function data(): collection {
6// Return collection of data
7}
8 
9public function columns(): array {
10// Return array of Column instances
11}
12 
13public function filters(): array {
14// Return array of Filter instances
15}
16 
17public function options(): array {
18// Return array of custom options
19}
Passing data to the table

Public Properties

To pass data to the component, either from a route or from an attribute in the <livewire> tag, you only need to declare it as a public property in the table component.

1&lt;livewire:mytable color_type="primary"&gt;
2 
3class MyTable extends YATBaseTable
4{
5public $color_type;
6...