Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

2 Datatables on the same view #53

Closed
pbreah opened this issue Oct 27, 2014 · 1 comment
Closed

2 Datatables on the same view #53

pbreah opened this issue Oct 27, 2014 · 1 comment

Comments

@pbreah
Copy link

pbreah commented Oct 27, 2014

I'm using your DatatablesBundle, great work. It is really useful.

I was looking at the documentation, and didn't see any mention on how to insert two or more Datatables on one view. Is this possible? if not, what would I need to do this?

This is my first project in Symfony 2.

Thank you

@stwe
Copy link
Owner

stwe commented Oct 27, 2014

Please try:

in your controller:

/**
 * Lists all Season entities.
 *
 * @Route("/", name="season")
 * @Method("GET")
 * @Template()
 *
 * @return array
 */
public function indexAction()
{
    $datatable1 = $this->get("sg_datatables.season");
    $datatable1->buildDatatableView();

    $datatable2 = $this->get("sg_datatables.chili");
    $datatable2->buildDatatableView();

    return array(
        "datatable1" => $datatable1,
        "datatable2" => $datatable2
    );
}

/**
 * Get all Season entities.
 *
 * @Route("/results1", name="season_results")
 *
 * @return \Symfony\Component\HttpFoundation\Response
 */
public function datatable1ResultsAction()
{
    /**
     * @var \Sg\DatatablesBundle\Datatable\Data\DatatableData $datatable
     */
    $datatable = $this->get("sg_datatables.datatable")->getDatatable($this->get("sg_datatables.season"));

    return $datatable->getResponse();
}

/**
 * Get all Chili entities.
 *
 * @Route("/results2", name="chili_results")
 *
 * @return \Symfony\Component\HttpFoundation\Response
 */
public function datatable2ResultsAction()
{
    /**
     * @var \Sg\DatatablesBundle\Datatable\Data\DatatableData $datatable
     */
    $datatable = $this->get("sg_datatables.datatable")->getDatatable($this->get("sg_datatables.chili"));

    return $datatable->getResponse();
}

and in your view:

{% block content_content %}

    <h1>Saison Liste</h1>

    {{ datatable_render(datatable1) }}

    <hr />

    <h1>Chili Liste</h1>

    {{ datatable_render(datatable2) }}

{% endblock %}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants