Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
533 stars 64 forks source link

BooleanFormatter Doesn't appear to add yes or no #117

Closed HawtDogFlvrWtr closed 1 year ago

HawtDogFlvrWtr commented 1 year ago

Database: Postgres Issue: Column 'Active' is data type boolean, but when formatting with BooleanFormatter, the value returned is blank. The class is setting text-danger and text-success correctly though. Do I have to populate the yes and no myself? It says in the function description that it does it automagically. I'm using standard bootstrap 5.2.3 to display the table. My Vers.

    "require": {
        "php": "^8.0.2",
        "ccxt/ccxt": "^2.6.8",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^3.0",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^4.2",
        "livewire/livewire": "^2.11",
        "okipa/laravel-table": "^5.2"
    },

Table:

<?php

namespace App\Tables;

use App\Models\Exchange;
use App\Models\Symbol;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;
use Okipa\LaravelTable\Formatters\BooleanFormatter;
use Okipa\LaravelTable\Formatters\DateFormatter;
use Okipa\LaravelTable\Table;
use Okipa\LaravelTable\Column;
use Okipe\LaravelTable\Formatters\Date;
use Okipa\LaravelTable\Filters\ValueFilter;

class SymbolsTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()->model(Symbol::class)
            ->query(function($query) {
                $query->select('symbols.*');
                $query->addSelect('exchanges.name as exchange_name');
                $query->join('exchanges', 'exchanges.id', '=', 'symbols.exchange_id');
            })
            ->numberOfRowsPerPageOptions([10, 15, 20, 25]);
    }

    protected function columns(): array
    {
        return [
            Column::make('exchange_name')->title('Exchange')->sortable(),
            Column::make('symbol')->title('Symbol')->searchable()->sortable(),
            Column::make('active')->title('Active?')->sortable()
                ->format(new BooleanFormatter()),
            Column::make('created_at')->title('Created On')
                ->format(new DateFormatter('m/d/Y H:i', 'America/New_York'))
                ->sortable(),
            Column::make('updated_at')->title('Modified On')
                ->format(new DateFormatter('m/d/Y H:i', 'America/New_York'))
                ->sortable()
                ->sortByDefault('desc'),
        ];
    }

    protected function results(): array
    {
        return [
            // The table results configuration.
            // As results are optional on tables, you may delete this method if you do not use it.
        ];
    }
}

image image

HawtDogFlvrWtr commented 1 year ago

Never mind. For anyone looking for the same answer...

After digging through the code more, I discovered that it's no longer the case that it automatically says yes or no. You have to change the setting in config/laravel-table.php for active and inactive.

I'm going to submit a change request that updates the text to reflect this.

Okipa commented 1 year ago

Hi @HawtDogFlvrWtr, this package is shipped with FontAwesome 5.

As so, the built-in BooleanFormatter does only display a FontAwesome active or inactive icon, according to the field value.

If you do not work with FontAwesome, you easily can publish and override the default config to define other icons.

In case you want to display anything else than icons, you also can create your own formatter to do so.

Keep in mind that you may use built-in elements as-is if you think they're convenient for you, but you may also use them as examples to create your own!