Giter Club home page Giter Club logo

filament-table-repeater's Introduction

Table Repeater Plugin

Latest Version on Packagist Total Downloads

table repeater opengraph image

Upgrade Guide for 2.x to 3.x

  1. Rename you use statements from Awcodes\FilamentTableRepeater to Awcodes\TableRepeater.
  2. Run npm run build to update your theme file.
  3. See Headers for changes to the headers() method.

Installation

You can install the package via composer:

composer require awcodes/filament-table-repeater

In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.

Important

If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.

  1. Import the plugin's stylesheet in your theme's css file.
@import '<path-to-vendor>/awcodes/filament-table-repeater/resources/css/plugin.css';
  1. Add the plugin's views to your tailwind.config.js file.
content: [
    '<path-to-vendor>/awcodes/filament-table-repeater/resources/**/*.blade.php',
]

Usage

This field has most of the same functionality of the Filament Forms Repeater field. The main exception is that this field can not be collapsed.

use Awcodes\TableRepeater\Components\TableRepeater;
use Awcodes\TableRepeater\Header;

TableRepeater::make('users')
     ->headers([
        Header::make('name')->width('150px'),
    ])
    ->schema([
        ...
    ])
    ->columnSpan('full')

Headers

To add headers use the headers() method. and pass in an array of Header components.

use Awcodes\TableRepeater\Header;

TableRepeater::make('users')
    ->headers([
        Header::make('name'),
        Header::make('email'),
    ])

Header Alignment

To align the headers of the table use the align() method, passing in one of the Filament Alignment enums.

use Filament\Support\Enums\Alignment;

Header::make('name')
    ->align(Alignment::Center)

Header Width

To set the width of the headers of the table use the width() method.

Header::make('name')
    ->width('150px')

Marking Columns as Required

To mark a column as required use the markAsRequired() method.

Header::make('name')
    ->markAsRequired()

Hiding the header

Even if you do not want to show a header, you should still add them to be compliant with accessibility standards. You can hide the header though with the renderHeader() method.

TableRepeater::make('users')
    ->headers(...)
    ->renderHeader(false)

Labels

By default, form component labels will be set to hidden. To show them use the showLabels() method.

TableRepeater::make('users')
    ->showLabels()

Empty State Label

To customize the text shown when the table is empty, use the emptyLabel() method.

TableRepeater::make('users')
    ->emptyLabel('There are no users registered.')

Alternatively, you can hide the empty label with emptyLabel(false).

Break Point

Below a specific break point the table will render as a set of panels to make working with data easier on mobile devices. The default is 'md', but can be overridden with the stackAt() method.

use Filament\Support\Enums\MaxWidth;

TableRepeater::make('users')
    ->stackAt(MaxWidth::Medium)

Appearance

If you prefer for the fields to be more inline with the table. You can change the appearance of the table with the streamlined() method.

TableRepeater::make('users')
    ->streamlined()

Extra Actions

TableRepeater supports the same extraItemActions() as the native Filament repeater. You may also add extra actions below the table with the extraActions() method. These will appear next to the 'Add' button or in place of the 'Add' button if it is hidden.

TableRepeater::make('users')
    ->extraActions([
        Action::make('exportData')
            ->icon('heroicon-m-inbox-arrow-down')
            ->action(function (TableRepeater $component): void {
                Notification::make('export_data')
                    ->success()
                    ->title('Data exported.')
                    ->send();
            }),
    ])

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-table-repeater's People

Contributors

aabosham avatar awcodes avatar billmn avatar bomshteyn avatar cannonb4ll avatar danielbehrendt avatar dependabot[bot] avatar donmbelembe avatar gergo85 avatar github-actions[bot] avatar howdu avatar kzrinski avatar malzariey avatar margarizaldi avatar monzer15 avatar oddvalue avatar rickdbcn avatar salimabsi avatar sandersjj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

filament-table-repeater's Issues

$visibleExtraItemActions doesn't exist

Filament Version

v3

Plugin Version

2.1.0

PHP Version

8.3

Problem description

Undefined variable $visibleExtraItemActions

Expected behavior

It to work

Steps to reproduce

install v2.1

Reproduction repository

No response

Relevant log output

No response

Console error on delete row

I have a table repeater field, when I add a new line and delete it just after, the row is deleted but I get this console message:
image

Placeholder::isRequired does not exist

Since the latest version our table repeater broke.
See flare: https://flareapp.io/share/4m4B0RJ7
This is our repeater:

Tab::make('Producten')
                                    ->schema([
                                        TableRepeater::make('products')
                                            ->relationship('orderItems')
                                            ->createItemButtonLabel('Regel toevoegen')
                                            ->label('')
                                            ->hideLabels()
                                            ->columnWidths([
                                                'sku' => '150px',
                                                'description1' => '350px',
                                                'description2' => '350px',
                                                'item_quantity' => '100px',
                                                'price' => '100px',
                                                'total_price' => '100px',
                                            ])
                                            ->schema([
                                               xxxxxx
                                            ]),

v3 branch - Missing Add Items Action

So I have the table repeater in a slideover() based form. If i set the max items to 3, the add item button doesnt disappear until Ive added 3 items, then click it again and it finally disappears. Should disappear after the 3rd one is added dont you think and not until you try to add a 4th?

Now probably related and the biggest problem, but if click that 3 times and the button disappears and I do not add or save any data and then cancel/close the slideover, then reopen it, there are no items (which there shouldnt be because i didnt save any), but the Add Items button is missing.

Issue when removing items

Filament Version

v3

Plugin Version

v2.0.2

PHP Version

PHP 8.2.4

Problem description

When you have multiple TableRepeaters component on the same form, it adds random elements to sibling repeaters.

See video.

I tried to use the ->key() method but the problem persisted.

Expected behavior

Items should be only added/removed to/from the repeater you are interacting with.

Steps to reproduce

use Awcodes\FilamentTableRepeater\Components\TableRepeater;
use Coolsam\FilamentFlatpickr\Forms\Components\Flatpickr;

// ...

Forms\Components\Tabs\Tab::make('Schedule')
    ->schema([
        TableRepeater::make('mondays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('tuesdays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('wednesdays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('thursdays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('fridays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('saturdays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),

        TableRepeater::make('sundays')
            ->schema([
                Flatpickr::make('start'),
                Flatpickr::make('end'),

            ]),
    ])
    ->columns(3)
    ->columnSpanFull();

Reproduction repository

No response

Relevant log output

No response

Dark mode table header bg issue.

Filament Version

v3

Plugin Version

2.x-dev

PHP Version

8.2

Problem description

Table heading design brakes in dark mode.

image

Expected behavior

Should match with dark mode.

Steps to reproduce

Just use in dark mode.

Reproduction repository

No response

Relevant log output

No response

v2.1 is broken on Filament 3.1 and 3.2 (Livewire Multiple Root Detected)

Filament Version

v3

Plugin Version

v2.1

PHP Version

PHP 8.3

Problem description

I received the following error when using TableRepeater 2.1 on Filament v 3.1 to v 3.2. Also tried this on a fresh install of Filament 3.1 and 3.2 and both returned the same error:

Livewire only supports one HTML element per component. Multiple root elements detected for component:

The temporary fix for now is to downgrade TableRepeater to 2.0 or use the default Filament Repeater.

Expected behavior

TableRepeater 2.1 to work on Filament

Steps to reproduce

Simply use TableRepeater with an eloquent relationship.

Reproduction repository

No response

Relevant log output

No response

defaultItems(0) breaks when no labels are provided

Filament Version

v3

Plugin Version

v2.1.0

PHP Version

PHP 8.3.0

Problem description

Using defaultItems(0) will result in a Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization error. A simple repeater will not issue this error and works as expected. The issue is resolved when using a custom label for each fields.

Expected behavior

Expected an empty repeater in the create form.

Steps to reproduce

I'm using this code

Section::make()->schema([
                TableRepeater::make('projectSpNatures')
                    ->relationship()
                    ->columnSpan('full')
                    ->schema([
                        Select::make('spNature_id')
                            ->relationship('spNature', 'name')
                            ->hiddenLabel(true)
                            ->required(),
                        TextInput::make('budget')
                            ->hiddenLabel(true)
                            ->numeric(),
                    ])
                    ->defaultItems(0)
                    ->cloneable()
                    ->orderColumn('sort_order')
                    ->mutateRelationshipDataBeforeSaveUsing(fn($record, $data) => $data['project_id'] = $record->project_id)
            ])
                ->hiddenOn(['view', 'edit']),

Adding a ->label("Custom label") for each field will resolve the issue.

Reproduction repository

No response

Relevant log output

No response

extraItemActions() not showing if all other actions (like clone, reorder, ...) are disabled

Filament Version

v3

Plugin Version

v3.0.2

PHP Version

PHP 8.3.0

Problem description

When all "default" actions per row are disabled, the row-actions column is not shown. This means that the extraItemActions are not displayed.

Expected behavior

The row actions column should be visible

Steps to reproduce

TableRepeater::make('myItems')
        ->headers([...])
        ->schema([...])
        ->extraItemActions([
                Action::make('someAction'),
        ])
        ->addable(false)
        ->reorderable(false)
        ->deletable(false)

Reproduction repository

No response

Relevant log output

No response

v3 branch - DefaultItems

Setting a defaultItems(1) with Filament v3 does not result in any default items. No errors, just no default items.

Darkmode table header isn't in the right color

Filament Version

v3

Plugin Version

v2.0.0

PHP Version

PHP 8.10

Problem description

The header is displayed white instead of dark grey.
This is caused by the opacity added to the background color in dark mode.

Besides this the rounding isn't working.

image

Expected behavior

The table header being grey

Steps to reproduce

Just a fresh install, with headers.
Then you see white headers.

Reproduction repository

No response

Relevant log output

No response

Alignment jumping

Filament Version

v3

Plugin Version

3.0.4

PHP Version

8.3.6

Problem description

Hello. I had an error with the alignment of the elements when I was selecting elements with a long and short name

2024-05-18.23.59.31.mov

Expected behavior

Length of items should be static size

Steps to reproduce

Here is the code:

private static function ingredientTab(): \Illuminate\Contracts\Support\Htmlable
{
    return Tab::make('Ингредиенты')
        ->schema([
            Section::make()
                ->schema([
                    TableRepeater::make('productIngredients')
                        ->label('')
                        ->relationship()
                        ->headers([
                            Header::make('name'),
                            Header::make('required'),
                        ])
                        ->showLabels()
                        ->renderHeader(false)
                        ->schema([
                            Select::make('ingredient_id')
                                ->label('')
                                ->relationship('ingredient', 'name'),
                            Toggle::make('required')
                                ->label('Обязательный'),
                        ])
                        ->defaultItems(0)
                        ->addActionLabel('Добавить')
                        ->columnSpan('full'),
                ])->maxWidth('full'),
        ]);
}

Problem in alignment of Select and Toggle components

Reproduction repository

No response

Relevant log output

No response

Select behaviour

I have a modal using this plugin, and I have an issue with select within the repeater (see image below):
image

I can't see the content of the select and the header of the table disappears.
Many thanks for your feedback

Select relationship value not retained after saving

Filament Version

v3

Plugin Version

v2

PHP Version

8.1

Problem description

Using a Form Select inside the repeater with a createOptionForm, the created option is saved and associated with the repeater relationship but, after save, the select is cleared. Refreshing the page then shows the select value.

TableRepeater::make('clientContacts')
    ->label('Contacts')
    ->relationship()
    ->schema([
        Forms\Components\Select::make('contact_id')
            ->relationship('contact', 'name')
            ->required()
            ->searchable()
            ->createOptionForm([
                Forms\Components\TextInput::make('name')
                    ->required(),
                Forms\Components\TextInput::make('email')
                    ->email(),
                Forms\Components\TextInput::make('office_phone')
                    ->tel(),
                Forms\Components\TextInput::make('mobile_phone')
                    ->tel()
                ])->createOptionModalHeading('Create Contact'),
        Forms\Components\TextInput::make('description')
    ])
Screen.Recording.2023-09-11.at.10.53.08.AM.mov

Expected behavior

The expected behavior is that the select value would remain after saving.

Steps to reproduce

In a form, add the TableRepeater referencing a relationship and within the TableRepeater schema, include a Select with a createOptionForm. Open an existing record that contains the TableRepeater and attempt to add a new relationship by clicking the suffix create action then save.

Reproduction repository

No response

Relevant log output

No response

does it work without admin panel ?

previously i am using the v1.0.0 without the admin panel and it work as it should be except the select behaviour as reported in #3 , now i upgrade it to v1.0.2 and the style break as below
image

any workaround to fix this as it only happen if not using the admin panel

Hidden Labels issue in (CheckboxList and radio buttons)

if we use the radio button or checkbox list,
and use hide labels then it is hiding the radios and checkboxes.

image

The solution is to change css slightly like

.filament-table-repeater-column.has-hidden-label label:not(.filament-forms-checkbox-list-component-option-label, .filament-forms-radio-component label)
{
/* css */
}

Thanks

Orderable ghosted selection

When a table is given the ability to be orderable, there is an interesting bug where it overlays more than just the row that is being manipulated. It looks to be a distance below selection as some of the top selections do not experience the same issue.

I attempted with the standard Repeater, and it does not occur.

Any thoughts?

Screen.Recording.2023-07-12.at.10.38.15.AM.mov

issue with stackAt(MaxWidth::Large)

Filament Version

v3

Plugin Version

v3

PHP Version

PHP 8.1

Problem description

I have an issue with Break Down feature, the fields dont appear between 768px and 1024px if I set the following

->stackAt(MaxWidth::Large)

Less than 768px :
Screenshot from 2024-02-06 11-36-59

Greater and equal to 768px :
Screenshot from 2024-02-06 11-36-44

Greater than 1024px :

Screenshot from 2024-02-06 11-36-18

Expected behavior

Labels to appear for each field.

Steps to reproduce

1 - Setting the stackAt option:

->stackAt(MaxWidth::Large)

2- Changing the width of the browser .
3- Refresh Page.

Reproduction repository

No response

Relevant log output

No response

TableRepeater & Form Actions

Filament Version

v3

Plugin Version

v2.0.0

PHP Version

PHP 8.2

Problem description

When using the new actions feature inside a table repeater:

Forms\Components\Actions::make([
    Forms\Components\Actions\Action::make('resetStars')
        ->icon('heroicon-m-x-mark')
        ->color('danger')
        ->requiresConfirmation()
        ->action(function () {
        }),
])

This breaks the repeater when using columnWidths(): Method Filament\Forms\Components\Actions::getName does not exist.

Expected behavior

To render the action buttons.

Steps to reproduce

Create a tablerepeater, use the columnWidths() method, and add this:

Forms\Components\Actions::make([
    Forms\Components\Actions\Action::make('resetStars')
        ->icon('heroicon-m-x-mark')
        ->color('danger')
        ->requiresConfirmation()
        ->action(function () {
        }),
])

Reproduction repository

No response

Relevant log output

No response

The documentation for the headers() method requires updating.

Filament Version

v3

Plugin Version

v2.1

PHP Version

PHP 8.3

Problem description

I could never get the headers() method to function as expected, decided to look into the source code to figure out what's happening.

In reference to the documentation, the table headers can be modified by passing an array of the desired headers to the headers() method. For example:

TableRepeater::make('product') ->headers(['Product Name', 'Quantity'])

However, it should be noted that the correct syntax involves including the field name as the key otherwise TableRepeater will simply use the default label of the fields.

TableRepeater::make('social') ->headers(['name' => 'Product Name', 'qty' -> 'Quantity'])

Expected behavior

For the headers to work

Steps to reproduce

Provide an array to the headers() method without specifying keys.

Reproduction repository

No response

Relevant log output

No response

v3 issue with hidden fields

Filament Version

v3

Plugin Version

v3.0.0

PHP Version

8.3

Problem description

The new version requires me to add headers, but if I have hidden inputs, they will break the layout. If I do not add a header, I will have an index out of range exception.

Expected behavior

Steps to reproduce

Add a hidden input

Reproduction repository

No response

Relevant log output

No response

TagsInput not working correctly

Filament Version

v3

Plugin Version

v2.0.0

PHP Version

PHP 8.1.0

Problem description

"TagsInput" is not working correctly. Let's imagine the following scenario:

use Filament\Forms\Components;
use Awcodes\FilamentTableRepeater\Components\TableRepeater;

TableRepeater::make('preview')
  ->key('tablePreview')
  ->schema([
      Components\TagsInput::make('grid_line')->disabled(),
      Components\TagsInput::make('grid_columns'),
  ])
  ->default([]),

Basically, when adding new lines and adding tags, whenever you delete the first record, the next one becomes a duplicate, for example:

Before delete:
image

After delete:
image

I ended up deleting the "Preto" line, but he ended up duplicating everything.

Expected behavior

The expectation would be not to duplicate "Amarelo", 33 and 34. As in the example below:

Correct ✅
image

Wrong ❌
image

Steps to reproduce

Normally use "Tablet Repeater" together with "Tags Input".

use Filament\Forms\Form;
use Filament\Forms\Components;
use Awcodes\FilamentTableRepeater\Components\TableRepeater;

public static function form(Form $form): Form
{
  return $form
    ->schema([
      TableRepeater::make('preview')
        ->key('tablePreview')
        ->schema([
            Components\TagsInput::make('grid_line')->disabled(),
            Components\TagsInput::make('grid_columns'),
        ])
        ->default([]),
    ]);
}

Add two lines with any tags, then delete the first.

Reproduction repository

No response

Relevant log output

No response

Undefined array key 0

Filament Version

v3

Plugin Version

v3.0.2

PHP Version

PHP 8.1.27

Problem description

ErrorException: Undefined array key 0 when creating a new Item:
image
Click on New:
image

Code:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('field1'),
Forms\Components\TextInput::make('field2'),
Forms\Components\TextInput::make('field3'),
\Awcodes\TableRepeater\Components\TableRepeater::make('details')
->relationship('details')
->schema([
Forms\Components\TextInput::make('field4'),
Forms\Components\TextInput::make('field5'),
Forms\Components\TextInput::make('field6')
->hidden(fn (string $operation): bool => $operation === 'view'),
]),
]);
}

Migration:
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('purchase_orders', function (Blueprint $table) {
$table->id();

        $table->string('field1');
        $table->string('field2');
        $table->string('field3');

        $table->timestamps();
    });

    Schema::create('purchase_order_details', function (Blueprint $table) {
        $table->id();

        $table->foreignId('purchase_order_id');
        $table->string('field4');
        $table->string('field5');
        $table->string('field6');

        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 */
public function down(): void
{
    Schema::dropIfExists('purchase_order_details');
    Schema::dropIfExists('purchase_orders');
}

Expected behavior

Display the creation form

Steps to reproduce

As explain above

Reproduction repository

No response

Relevant log output

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.