DataTable showing No data when implementing server side using laravel

DataTable showing No data when implementing server side using laravel

tigranatigrana Posts: 1Questions: 1Answers: 0

i have tried data table in laravel but still gettting no data
My script is var TableAjax = function ()
{

var handleRecords = function ()
{

    $("#datatable_custom").DataTable(
    {

        onSuccess: function (grid) {
            // execute some code after table records loaded
        },
        onError: function (grid) {
            // execute some code on network or other general error  
        },
        onDataLoad: function(grid) {
            // execute some code on ajax data load
        },
        loadingMessage: 'Loading...',
        dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options 

            // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
            // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/scripts/datatable.js). 
            // So when dropdowns used the scrollable div should be removed. 
            //"dom": "<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>",

            "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
            "processing": true,
            "ServerSide": true,//enable server side data
            "lengthMenu": [
                [10, 20, 50, 100, 150, -1],
                [10, 20, 50, 100, 150, "All"] // change per page values here
            ],
            "pageLength": 10, // default record count per page
            //"ajax":  "http://localhost/laravel/admin/orders", // ajax source,
            "ajax": {
                "url": "http://localhost/laravel/admin/orders",
                "type": "POST"
            },
            "columns": [
                { "data": "name" },
                { "data": "email" },
                { "data": "phone" },
                { "data": "address" },
                { "data": "status" },
                { "data": "created_at" }
            ],
            "order": [
                [1, "asc"]
            ]// set first column as a default sort by asc
        }
    });

}

return {

    //main function to initiate the module
    init: function () {
        handleRecords();
    }

};

}();

and my controller function is
public function getOrders(Request $request)
{
$orders=Task1::all();
//return Datatables::of($users)->make(true);

    if($request->ajax())
    return json_encode($orders);
    return view('adminpanel.orders');
}

I am currently using laravel 5.2

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,217Questions: 1Answers: 10,415 Site admin
    Answer ✓

    "ServerSide"

    Should be serverSide. Javascript is case sensitive.

    Allan

This discussion has been closed.