allanmcarvalho / cakephp-datatables

A CakePHP 3 DataTables automagic plugin
MIT License
6 stars 12 forks source link

Response doesn't show up #26

Open acastaneiras opened 4 years ago

acastaneiras commented 4 years ago

Hello, I'm trying to implement your plugin in my application, but I don't know what I'm doing wrong, the table with the columns is displaying correctly in the view but there isn't any data in there.

My Controller:

<?php

namespace App\Controller;

use App\Controller\AppController;
use Cake\Event\Event;
use DataTables\Controller\DataTablesAjaxRequestTrait;

/**
 * Societies Controller
 *
 * @property \App\Model\Table\SocietiesTable $Societies
 *
 * @method \App\Model\Entity\Society[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
 */
class SocietiesController extends AppController
{
    use DataTablesAjaxRequestTrait;

    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('DataTables.DataTables', ['language' => ['url' => 'Spanish.json']]);

        $this->DataTables->createConfig('SocietiesIndex')
            ->table('Societies')
            ->column('name', ['label' => 'Name'])
            ->column('acronym', ['label' => 'Acronym'])
            ->column('anonymous', ['label' => 'Anonymous'])
            ->column('address', ['label' => 'Address'])
            ->column('actions', ['label' => 'Actions', 'database' => false]);
    }

    public function index()
    {
        $this->DataTables->setViewVars("SocietiesIndex");
    }

At my index.ctp i have:

<?= $this->DataTables->render('SocietiesIndex', ['class' => 'table table-striped table-bordered dataTable no-footer', 'OthersAttr' => '...']) ?>

And in "Template/Societies/datatables/societies_index.ctp":

<?php
foreach ($results as $result)
{
    $this->DataTables->prepareData([
        $result->name,
        $result->acronym,
        $result->anonymous,
        $result->address,
        $this->Html->link('Delete', ['action' => 'delete', $result->id])
    ]);
}
echo $this->DataTables->response();
allanmcarvalho commented 4 years ago

With debug set as true, on de developer tools of your browser you can see the response of the DataTables ajax request. In the response you will can see what's wrong. Give us this information.

acastaneiras commented 4 years ago

Request: imagen

Variables: imagen

joakim-emagine commented 4 years ago

@Syloid do you get a javascript error?