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

Undefined index: orderable #202

Closed
antonioribeiro opened this issue Mar 4, 2015 · 1 comment
Closed

Undefined index: orderable #202

antonioribeiro opened this issue Mar 4, 2015 · 1 comment

Comments

@antonioribeiro
Copy link
Contributor

I have it working for some tables in this package: https://github.com/antonioribeiro/tracker/, but now I'm getting this error in one table only. This is how I'm using it:

This is the view responsible for rendering the datatable:

@extends(Config::get('pragmarx/tracker::stats_layout'))

@section('page-contents')
    <table id="table_div" class="display" cellspacing="0" width="100%"></table>
@stop

@section('inline-javascript')
    @include(
        'pragmarx/tracker::_datatables',
        array(
            'datatables_ajax_route' => route('tracker.stats.api.events'),
            'datatables_columns' =>
            '
                { "data" : "name",  "title" : "Name", "orderable": true, "searchable": false },
                { "data" : "total", "title" : "# of occurrences in the period", "orderable": true, "searchable": false },
            '
        )
    )
@stop

This is the datatable part of the generated HTML:

$(document).ready(function() {
    $('#table_div').dataTable( {
        "processing": true,
        "serverSide": true,
        "bFilter": false,
        "ajax": "http://dev.l4.com/stats/api/events",
        "columnDefs": [ {
            "targets": "_all",
            "defaultContent": ""
        } ],
        "columns": [

                { "data" : "name",  "title" : "Name", "orderable": true, "searchable": false },
                { "data" : "total", "title" : "# of occurrences in the period", "orderable": true, "searchable": false },

        ]
    } );
} );

This is the controller method called by ajax, which should return the datatable to the JS datatables:

    public function apiEvents()
    {
        $query = Tracker::events($this->minutes, false);

        return Datatables::of($query)->make(true);
    }

The variable $query is of type:

Illuminate\Eloquent\Query\Builder

And if I do $query->toSql() I get

select 
    "tracker_events"."id", 
    "tracker_events"."name", 
    count(tracker_events_log.id) as total 
from "tracker_events" 
inner join "tracker_events_log" on "tracker_events_log"."event_id" = "tracker_events"."id" 
where "tracker_events_log"."updated_at" >= ? 
and "tracker_events_log"."updated_at" <= ? 
group by "tracker_events"."id", "tracker_events"."name" order by "total" desc

In the browser console I see it's generating the following error:

GET 

http://dev.l4.com/stats/api/events?draw=1&columns%5B0%5D%5Bdata%5D=name&col…art=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1425503969194 500 

(Internal Server Error)

EDIT: my nginx log is showing a different url:

172.17.0.100 - - [04/Mar/2015:18:59:40 -0300] "GET /stats/api/events?draw=1&columns%5B0%5D%5Bdata%5D=name&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=false&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=total&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=false&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1425506392042 HTTP/1.1" 500 50306 "http://dev.l5.com/stats?page=events" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36"

/EDIT

But it looks like the URL is somehow wrong, because it has not the orderable column you are looking for in

$this->input['columns'][$i]['orderable']

As you can see here:

bllim

Am I doing something wrong?

@antonioribeiro
Copy link
Contributor Author

It was a bug of yours: #203

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

1 participant