flavorly / vanilla-components

A lightweight, flexible & customizable UI library for Vue 3, styled with Tailwind CSS.

Home Page:https://vanilla-components.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding constructor to class for Datatable requires a Name

juliancarstairs opened this issue · comments

commented

I have a generic class taken from the skeleton example on docs

If I add a constructor to it so an example:

namespace App\Datatables\Users;

use Flavorly\VanillaComponents\Datatables\Datatable;
use Flavorly\VanillaComponents\Datatables\Options\General\Options;

class User extends Datatable
{
   public function __construct($id)
    {
        $this->id = $id;
    {
    public function query(): mixed
    {
        return User::query()->where('user_id', $this->id);
        
        // You can also return a closure or a relationship here
        // return fn() => User::query()->where('user_id', auth()->id());
        // Auth::user()->payments();
    }
    
    public function fetchEndpoint(): ?string
    {
        // Endpoint where the datatable will fetch the data from
        return route('datatables.demo');
    }
    
    public function columns(): array
    {
        return [
           // Columns go here
        ];
    }

    public function filters(): array
    {
        return [
            // Filters go here
        ];
    }

    public function actions(): array
    {
        return [
            // Actions go here
        ];
    }

    public function options(): array| Options
    {
        return Options::make()->refreshable()->hideSearchBar();
    }
}

I get the following error. I tried also defining the Name attribute on the class but that did not seem to work either.

Flavorly\VanillaComponents\Datatables\Datatable::getName(): Return value must be of type string, null returned

commented

I have used parent::setup() after my declaration and seems to fix it, is this the correct way of going about things?

All Datatables should implement a getName() name, maybe i forgot to mention on the docs, this is because filters and other stuff are prefixed by the name, so in case you want to have 2 datatables on same page, they would still work normally.

commented

I think you could implement an interface to ensure that this property is available on all Datatables, currently it uses the reflection class to set get name. just a thought. thanks