tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

Is there are way to show two unrelated datatables on a single page? #32

Closed glapworth closed 11 years ago

glapworth commented 11 years ago

I have an application, which has a view that needs to contain two datasets - lets say I have View Customer action in my controller. I want to show all contacts that exist with this customer, but I also wish to show all open support requests for this customer. Both of these models are related customer, but not to each other.

What I tried: In my controller, I put the following code

  $dTcolumns = array(
    'Contact' => array(
      'id' => true,
      'first_name' => true,
      'email' => true,
      'telephone0' => true,
      'Action' => null
    ),
    'Call' => array(
      'id' => true,
      'priority' => true,
      'user' => true,
      'closed' => true,
      'date' => true,
      'Action' => null
    )
  );

  $this->DataTable->settings['triggerAction'] = 'view_client';
  $this->DataTable->settings['columns'] = $dTcolumns;
  $this->layout = "datatables";
  $this->DataTable->paginate = array('Contact','Call');   

  $this->layout = "datatables";
  $this->set('client', $currentClient); 
  $this->render('test_view_client');

And in my View, I have :

  echo $this->DataTable->render('Call',array('class' => 'dataTable table table-striped table-bordered'), $js_call);
  echo $this->DataTable->render('Contact',array('class' => 'dataTable table table-striped table-bordered'), 

$js_contact);

$js_call and $js_contact are both arrays containing the settings for each datatable.

Before I carry on with this path, I am just wondering if what I want is possible.

Cheers, Gareth

tigrang commented 11 years ago

Yes. It was designed with that in mind.

glapworth commented 11 years ago

Any tips or examples to show how to use it that way?

tigrang commented 11 years ago

merge your $dtColumns array with $this->DataTable->settings instead of $this->DataTable->settings['columns'] like so

$this->DataTable->settings = array('FirstModel' => array('columns' => ....), 'SecondModel' => array('columns' => ...)); The rest looks correct.

On Thu, Jun 13, 2013 at 8:58 AM, glapworth notifications@github.com wrote:

Any tips or examples to show how to use it that way?

— Reply to this email directly or view it on GitHubhttps://github.com/tigrang/cakephp-datatable/issues/32#issuecomment-19401436 .

glapworth commented 11 years ago

Wonderful, Thanks :)