Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Table Bundle Laravel Package

araise/table-bundle

View on GitHub
Deep Wiki
Context7

Table Configuration

In the table configuration you define all the columns of the table

Table Options

All Options are as constants in Table class.

  • title: String|Null
  • searchable: Boolean, default: false
  • sortable: Boolean, default: true
  • attr:
  • table_attr:
  • default_limit : Int, dafault: 25
  • limit_choices: Int, possible values: [10, 25, 50, 100, 200]
  • table_box_template: String, box template, default: [@araiseTable](https://github.com/araiseTable)/table.html.twig
  • table_template: String, table template, default: [@araiseTable](https://github.com/araiseTable)/tableOnly.html.twig
  • default_sort:
  • content_visibility: Array with option, default:
    • content_show_pagination: Boolean, default: true
    • content_show_result_label: Boolean, default: true
    • content_show_header: Boolean, default: true
    • content_show_entry_dropdown: Boolean, default: true
    • content_show_pagination_if_page_total_less_than_limit: Boolean, default: true
  • sub_table_collapsed: Boolean or callable, default: true

Collapse Sub-Tables

By default, sub-tables will be rendered collapsed. This can be changed by setting the sub_table_collapsed option to either false or pass a callable that returns a boolean.

$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, false);

Note that if you pass a function, you will get the current row as an argument. You can use this to only expand certain rows:

// Expand only users with an email
$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, function(array|object $row) {
    if(!$row instanceof User) {
        return true;
    }
    if($row->getEmail() !== null) {
        return false;
    }
    return true;
});

Column Options

Example

$table
    ->addColumn('firstname')
    ->addColumn('lastname')
    ->addColumn('birthday', null, [
        'sortable' => false,
        'formatter' => UserBirthdayFormatter::class,
    ])
;

For the columns you have a few options to tweak how they behave:

All Options are as constants in Column class.

  • label: String, column name
  • callable: Function, callable to get the data
  • accessor_path: String, defaults to the acronym
  • formatter: Formatter
  • sort_expression: String, example: 'trainerGroup.name'

Footer Columns

In this example we would like to add a count of the content at the end of our table. We can to this by adding a footer column like so:

$data= [
    [
        'id' => 1,
    ],
    [
        'id' => 2,
    ]
];

$table
    ->setFooterData(['count' => count($data)])
    ->addFooterColumn('totalLabel', null, [
        Column::OPT_CALLABLE => fn (array $content) => 'Total',
    ])
    ->addFooterColumn('count', null, [
        Column::OPT_CALLABLE => fn(array $content) => $content['count'],
    ])
;

Note that this is only a simple example. The data could easily be replaced with an array of entities for example.

Action Columns

Action Columns are here to link to other pages (f.ex. link to edit or view). This column has a special template to render the links.

Add A Table Action

You can add your own table actions like this:

$table->addAction('test', [
    Action::OPT_LABEL => 'Test Button',
    Action::OPT_ROUTE => self::getRoute(Page::SHOW),
    Action::OPT_ROUTE_PARAMETERS => fn ($row) => [
        'id' => $row->getId(),
    ],
]);

As per default, the addAction()-method will use the Action class for your configuration.

To change which rows can use an action, try using the TableAction class and its visibility option instead:

$table->addAction('test', [
    Action::OPT_LABEL => 'Test Button',
    Action::OPT_ROUTE => self::getRoute(Page::SHOW),
    Action::OPT_ROUTE_PARAMETERS => fn ($row) => [
        'id' => $row->getId(),
    ],
    TableAction::OPT_VISIBILITY => fn($row) => $row->getId() % 2 === 0,
], TableAction::class);

You can also simply set the visibility to a boolean instead of giving it a function:

TableAction::OPT_VISIBILITY => false

Options

Take a look at the constants on the Action or the TableAction class. You can use all of these to further configure your action.

Filters

Our tables can be filtered very easily. Most of it works automatically. See chapter Filters for more info.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
bugban/symfony
beyonder-capi/workflow-extensions-bundle
beyonder-capi/job-queue-bundle
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin