Weave 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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels