tabalinas/jsgrid

Laravel 5 - Push data to the controllers

Open

#990 opened on Jan 3, 2018

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (1,520 stars) (356 forks)batch import
help wanted

Description

I am trying to implement a sample CRUD project of jsgrid on laravel 5.

Problem

I have implemented the controller as the following:

$(function () {

    $("#jsGrid").jsGrid({
        width: "100%",
        height: "400px",
        
        filtering: true,
        inserting: true,
        editing: true,
        sorting: true,
        paging: true,
        autoload: true,

        data: storedTasks,
        controller: {
            loadData: function(filter) {
                console.log("Filter: "+ filter)
                return $.ajax({
                    type: "GET",
                    url: "/tasks/",
                    data: storedTasks
                });
            },
            insertItem: function(item) {
                console.log("item: " + item)
                return $.ajax({
                    type: "POST",
                    url: "/tasks/",
                    data: storedTasks
                });
            },
            updateItem: function(item) {
                return $.ajax({
                    type: "PUT",
                    url: "/tasks/",
                    data: item
                });
            },
            deleteItem: function(item) {
                return $.ajax({
                    type: "DELETE",
                    url: "/tasks/",
                    data: item
                });
            }
        },
        fields: [{
                name: "Name",
                type: "text",
                width: 150,
                validate: "required"
            },
            {
                name: "Created_At",
                type: "text",
                width: 200
            },
            {
                name: "Updated_At",
                type: "text",
                width: 200
            },
            {
                name: "revision_status",
                type: "checkbox",
                title: "Revision Status",
                sorting: false
            },
            {
                type: "control"
            }
        ]
    });
});

My routes in my backend look like the following:

Route::resource('/tasks', 'TaskController'); with the following routes:

+--------+-----------+------------------------------+----------------------+---------------------------------------------------------------+----------------------------------------------+
| Domain | Method    | URI                          | Name                 | Action                                                        | Middleware
                        |
+--------+-----------+------------------------------+----------------------+---------------------------------------------------------------+----------------------------------------------+
|        | GET|HEAD  | api/user                     |                      | Closure                                                       | api,auth:api
                        |
|        | GET|HEAD  | tasks                        | tasks.index          | App\Http\Controllers\TaskController@index                     | web
                        |
|        | POST      | tasks                        | tasks.store          | App\Http\Controllers\TaskController@store                     | web
                        |
|        | GET|HEAD  | tasks/create                 | tasks.create         | App\Http\Controllers\TaskController@create                    | web
                        |
|        | GET|HEAD  | tasks/{task}                 | tasks.show           | App\Http\Controllers\TaskController@show                      | web
                        |
|        | PUT|PATCH | tasks/{task}                 | tasks.update         | App\Http\Controllers\TaskController@update                    | web
                        |
|        | DELETE    | tasks/{task}                 | tasks.destroy        | App\Http\Controllers\TaskController@destroy                   | web
                        |
|        | GET|HEAD  | tasks/{task}/edit            | tasks.edit           | App\Http\Controllers\TaskController@edit                      | web
                        |
+--------+-----------+------------------------------+----------------------+---------------------------------------------------------------+----------------------------------------------+

Any suggestions why no event is fired in the frontend controller or are my backend routes wrong?

I appreciate your reply!

Contributor guide