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

Array Data Loader

The standard data loader is the DoctrineDataLoader. It loads data from a database table. Also when using the full araise framework, mostly the data is stored in a database.

There are cases where you just need to dispaly a table with data from an array. For this case the ArrayDataLoader is the right choice.

Usage

Controller/DefaultController.php:

namespace App\Controller;

use araise\TableBundle\DataLoader\ArrayDataLoader;
use araise\TableBundle\Factory\TableFactory;
use araise\TableBundle\Table\Table;
use Doctrine\Common\Collections\ArrayCollection;
use Faker\Factory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{

    public function __construct(protected TableFactory $tableFactory)
    {
    }

    #[Route('/', name: 'index')]
    public function indexAction(): Response
    {
        $table = $this->tableFactory->create('project', ArrayDataLoader::class, [
            Table::OPT_DATALOADER_OPTIONS => [
                ArrayDataLoader::OPT_DATA => $this->getTestDataArray(),
            ],
        ]);
        $table
            ->addColumn('Name', null, [
                'accessor_path' => '[name]',
            ])
            ->addColumn('Phone', null, [
                'accessor_path' => '[phone]',
            ])
            ->addColumn('Firma', null, [
                'accessor_path' => '[company]',
            ])
        ;

        return $this->render('index.html.twig', [
            'table' => $table,
        ]);
    }

    protected function getTestDataArray(int $many = 200): ArrayCollection
    {
        $faker = Factory::create();
        $faker->seed(1234); // to always get the same data
        $col = new ArrayCollection();
        for ($i = 1; $i <= $many; $i++) {
            $col->add([
                'name' => $faker->name(),
                'phone' => $faker->phoneNumber(),
                'company' => $faker->company(),
            ]);
        }
        return $col;
    }

}

templates/index.html.twig:

{% extends 'base.html.twig' %}

{% block body %}
    {{ araise_table_render(table) }}
{% endblock %}

You could also use araise_table_only_render in your twig template, this will skip the pagination and filters.

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