volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

Laravel 5 - Uncaught TypeError: $(...).jtable is not a function #1752

Open cladon opened 9 years ago

cladon commented 9 years ago

In my controller i have a methode

 $users = leerplan::all()->toArray();

    $result = array(
        'Result' => 'OK',
        'Records' => $users
    );

// return dd($result); // Show the page return view('jtable.index', compact('result'));

In my view i have the next code

......

$(document).ready(function () {

    //Prepare jTable
    $('#PeopleTableContainer').jtable({
        title: 'Table of people',
        actions: {
            listAction: '/jtable',
            createAction: '',
            updateAction: '',
            deleteAction: ''
        },
        fields: {
            id: {
                key: true,
                create: false,
                edit: false,
                list: false
            },
            leerplannummer: {
                title: 'Author Name',
                width: '40%'
            },
            ingang: {
                title: 'Age',
                width: '20%'
            }

        }
    });

    //Load person list from server
    $('#PeopleTableContainer').jtable('load');

...

Any idea what causes the typeError?

cladon commented 9 years ago

In my controller i convert the array to json with the next result

"{"Result":"OK","Records":[{"id":1,"leerplannummer":"D125\/GHBG125\/lMLKM","ingang":"2015","created_at":"2015-06-08 14:57:54","updated_at":"2015-06-08 14:57:54"},{"id":2,"leerplannummer":"dsfdsds","ingang":"sdsdfsd","created_at":"2015-06-08 14:58:57","updated_at":"2015-06-08 14:58:57"},{"id":3,"leerplannummer":"leerplan 34","ingang":"2015","created_at":"2015-06-08 18:58:51","updated_at":"2015-06-09 20:16:29"}]}"

I have done the next changes in my view

jtable-1

The TypeError stil exist

cmdrcoke commented 9 years ago

You need to return the result as JSON.

Try following this example from Eman.

  $order = explode(" ", Input::get('jtSorting'));
    $data = Users::orderBy($order[0], $order[1])
         ->take(Input::get('jtPageSize'))
         ->skip(Input::get('jtStartIndex'));
    return Response::json(array(
        'Result' => 'OK',
        'TotalRecordCount' => $data->count(),
        'Records' => $data->get()->toArray()
    ));