tigrang / cakephp-datatable

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

TypeError: undefined is not an object (evaluating 'c.length') #77

Open MMasterson opened 6 years ago

MMasterson commented 6 years ago

Hey @tigrang

I'm not sure how active this project is still, but I am running into an issue and I can't seem to figure out why. I have followed the Basic Usage Multiple Tables exactly, and ran into the admin_ prefix issue. I was able to solve it with information from issue #70.

However, once patching that issue I have run into a datatables javascript error TypeError: undefined is not an object (evaluating 'c.length')

Any ideas on why I am receiving this issue?

Controller

public $components = array('Paginator', 'Session', 'Component1', 'Component2','DataTable.DataTable' => [
        'Order' => [
            'columns' => [
                'id'
            ]
        ],
    ]);
public $helpers = [
        'DataTable.DataTable',
    ];

public admin_index() {
...
        $this->DataTable->setViewVar(['Order']);
...
}

order.ctp

<?php
foreach ($dtResults as $result) {
    $this->dtResponse['aaData'][] = array(
        $result['Order']['id']
    );
}

Index ctp echo $this->DataTable->render('Order');

tigrang commented 6 years ago

Hi,

This project is has not been active for a long time. Let's see if we can figure out what's wrong though.

Can you provide the javascript block that's generated as well as the request/response for datatable?

MMasterson commented 6 years ago

@tigrang,

Yeah I've noticed haha, you were just my only resource after hours of trying to fix this. Any help is appreciated!

As for the JS block, I'm unsure of which you're referring to - this is the block that is giving me problems

function ub(a, b) {
        var c = ta(a, b),
            d = b.sEcho !== k ? b.sEcho : b.draw,
            e = b.iTotalRecords !== k ? b.iTotalRecords : b.recordsTotal,
            f = b.iTotalDisplayRecords !== k ? b.iTotalDisplayRecords : b.recordsFiltered;
        if (d) {
            if (1 * d < a.iDraw)
                return;
            a.iDraw = 1 * d
        }
        na(a);
        a._iRecordsTotal = parseInt(e, 10);
        a._iRecordsDisplay = parseInt(f, 10);
        d = 0;
        for (e = c.length; d < e; d++)
            M(a, c[d]);
        a.aiDisplay = a.aiDisplayMaster.slice();
        a.bAjaxDataGet = !1;
        N(a);
        a._bInitComplete ||
        ua(a, b);
        a.bAjaxDataGet = !0;
        C(a, !1)
    }

and the Datatables request

index/processDataTableRequest?config=Order&sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&_=1516765047312

tigrang commented 6 years ago

If you're using Chrome, open network tab and right click the request, then copy -> copy as curl.

MMasterson commented 6 years ago

cURL Request

curl 'http://localhost/PROJECT/admin/orders/processDataTableRequest?config=Order&sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&_=1516857840467' -H 'Cookie: toolbarDisplay=hide; CAKEPHP=dbltp217j8getin1b8qm9im317' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://localhost/PROJECT/admin/orders/index' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --compressed

cURL Response

{
    "response": {
        "success": false,
        "message": "Invalid request",
        "data": [],
        "errors": []
    }
}
tigrang commented 6 years ago

Do you see a block of javascript that looks like https://github.com/tigrang/cakephp-datatable/blob/master/View/Helper/DataTableHelper.php#L88 in page source? Can you also provide that?

MMasterson commented 6 years ago

$(document).ready(function() {
--
  | $('.dataTable').each(function() {
  | var table = $(this);
  | var settings = dataTableSettings[table.attr('data-config')];
  | table.dataTable(settings);
  | });
  | });
MMasterson commented 6 years ago

hey @tigrang have you been able to figure anything out?