GithubHelp home page GithubHelp logo

Multiple grids? about apydatagridbundle HOT 15 CLOSED

apy avatar apy commented on May 18, 2024
Multiple grids?

from apydatagridbundle.

Comments (15)

Abhoryo avatar Abhoryo commented on May 18, 2024

You use the same object twice. You have to call again the grid service.

<?php

// First Grid
$grid1 = $this->get('grid');

$grid1->setId('grid1');
$source1 = new Entity(OneEntity);
$grid1->setSource($source1);

// And now the second:
$grid2 = $this->get('grid');

$grid2->setId('grid2');
$source2 = new Entity(SecondEntity);
$grid2->setSource($source2);

if ( $grid1->isReadyForRedirect() || $grid2->isReadyForRedirect() )
{
    // Data are stored, do redirect
    return new RedirectResponse($this->generateUrl($this->getRequest()->get('_route')));
}
else
{
    // To obtain data for template you need to call prepare function
    return $this->render(
        'MyProjectMyBundle::my_grids.html.twig', 
        array(
            'data1' => $grid1->prepare(), 
            'data2' => $grid2->prepare()
        )
    );
}

Do you confirm @Sorien ?

from apydatagridbundle.

print avatar print commented on May 18, 2024

Thanks for the response.

Yes i have taken the same in my testsuite, but the error still is "Source can be set just once".
I think the grid service manage multiple grids with one object by ids the twig tag says:

public function getGrid($grid, $theme = null, $id = '')

The tag gets the grid by id from one grid object.

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 18, 2024

I've never tested multiple grids yet. I'll try to make it work.

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 18, 2024

We'll wait for Sorien :D

from apydatagridbundle.

print avatar print commented on May 18, 2024

Ok let's wait, thanks for the trouble!

from apydatagridbundle.

 avatar commented on May 18, 2024

i'm not sure where is problem, it should be working, i'll look at it today ...

for now try this $grid_1 = $this->get('grid'); $grid_2 = clone $grid_1;

or

look at https://github.com/S0RIEN/DataGridBundle/blob/master/Resources/config/services.xml and define new service like

   <service id="my_second_grid" class="%grid.base.class%">
        <argument type="service" id="service_container" />
    </service>

and then

call $this->get('grid') and $this->get('my_second_grid') it should solve your problem

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 18, 2024

I'll already try these solutions and we get another problems.

from apydatagridbundle.

print avatar print commented on May 18, 2024

Same here :)

I have checked cloning and this brings trouble with the filter and sortings, the columns from my entitys will be "mixed".

And define a second service in sevice.xml brings this error: No suitable Column Extension found for column type: text

from apydatagridbundle.

 avatar commented on May 18, 2024

ok i've fixed cloning and service so use it like this

    $grid = $this->get('grid');
    $grid2 = $this->get('grid'); // or clone $grid;

    $grid->setSource(new Entity('Invoice:Invoice'));
    $grid->setId('first');

    $grid2->setSource(new Entity('Invoice:InvoiceReceived'));
    $grid2->setId('second');

    if ($grid->isReadyForRedirect() || $grid2->isReadyForRedirect())
    {
        return new RedirectResponse($this->generateUrl($this->getRequest()->get('_route')));
    }
    else
    {
        return $this->render('Invoice:Invoice:index.html.twig', array('data' => $grid->prepare(), 'data2' => $grid2->prepare()));
    }

pls let me know if its ok

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 18, 2024

It works for me, thx.

from apydatagridbundle.

print avatar print commented on May 18, 2024

Thanks!

My 2 grids comes up now, but sorting my grids makes trouble.
I have 2 different entitys on my page with diffrent columns.
When I sort grid1 so grid2 will always be sort if they has a column with the same name.
On sort a column that only exist in one grid i became this error: Column with id "diffrent" doesn't exists".

I think it's a problem with the paramater "grid__id_" on the sort columns, this id is for both grids the same.

from apydatagridbundle.

print avatar print commented on May 18, 2024

Ok i think the problem is in the twig function "getGridUrl($section, $grid, $param = null)" or a little deeper in getHash() or getId().

But i have no idea where i can begin to find the error, so i think its a good idea to wait a little for sorien :)

from apydatagridbundle.

 avatar commented on May 18, 2024

i've fixed generating hash in grid, and setId needs to be defined before setting source like example below

$grid = $this->get('grid');
$grid2 = $this->get('grid'); // or clone $grid;

$grid->setId('first');
$grid->setSource(new Entity('Invoice:Invoice'));

$grid2->setId('second');
$grid2->setSource(new Entity('Invoice:InvoiceReceived'));

from apydatagridbundle.

print avatar print commented on May 18, 2024

Thanks for your time, it work's now for me.

from apydatagridbundle.

 avatar commented on May 18, 2024

thx for bug reports, closing ticket ...

from apydatagridbundle.

Related Issues (20)

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.