Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple grids? #40

Closed
print opened this issue Oct 14, 2011 · 15 comments
Closed

Multiple grids? #40

print opened this issue Oct 14, 2011 · 15 comments
Milestone

Comments

@print
Copy link

print commented Oct 14, 2011

Hi!

i have tested youre grid in my app and its a wonderfull bundle, but i have problems with multiple grids on the same page and i doesent know what's wrong.

$grid = $this->get('grid');

// First Grid
$grid->setId('grid1');
$source = new Entity(OneEntity);
$grid->setSource($source);

// And now the second:

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

Error: Source can be set just once

I'm not sure if I understood this function correctly?

I hope you can get me a short tip.

Thanks for your time.

@Abhoryo
Copy link
Member

Abhoryo commented Oct 14, 2011

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 ?

@print
Copy link
Author

print commented Oct 15, 2011

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.

@Abhoryo
Copy link
Member

Abhoryo commented Oct 15, 2011

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

@Abhoryo
Copy link
Member

Abhoryo commented Oct 15, 2011

We'll wait for Sorien :D

@print
Copy link
Author

print commented Oct 15, 2011

Ok let's wait, thanks for the trouble!

@ghost
Copy link

ghost commented Oct 15, 2011

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

@Abhoryo
Copy link
Member

Abhoryo commented Oct 15, 2011

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

@print
Copy link
Author

print commented Oct 15, 2011

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

@ghost
Copy link

ghost commented Oct 15, 2011

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

@Abhoryo
Copy link
Member

Abhoryo commented Oct 15, 2011

It works for me, thx.

@print
Copy link
Author

print commented Oct 16, 2011

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.

@print
Copy link
Author

print commented Oct 16, 2011

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 :)

@ghost
Copy link

ghost commented Oct 16, 2011

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'));

@print
Copy link
Author

print commented Oct 16, 2011

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

@ghost
Copy link

ghost commented Oct 16, 2011

thx for bug reports, closing ticket ...

@ghost ghost closed this as completed Oct 16, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants