2

I have a site that's running Laravel 5 and I'd like to create a Webix datatable within it. My understanding of Webix datatables is that these tables can be set to load data from Laravel database by using a controller, but I do not see any information on how datatable information is read and saved when the datatable is set to editable.

When the datatable is editable, do I still need to create a controller for read and write to the database? And if so, how do I know what data was changed/needs to be updated in the database?

Sakamoto Kazuma
  • 2,573
  • 7
  • 34
  • 75

1 Answers1

1

For examples on how to load and save data in php, have a look at these:

http://docs.webix.com/desktop__custom_serverside.html#dataloading http://docs.webix.com/desktop__dataconnector.html http://docs.webix.com/samples/14_dataprocessor/08_custom_urls.html

For the javascript side using webix you can call save

dtable = new webix.ui({
    container:"test",
    view:"datatable",
    editable: true
    columns:[
        { id:"id", header:"Id", width:80},
        { id:"name", header:"Name", width:100},
        { id:"email", header:"Email", width:100}
    ],
    url: "data/data_load.php",
    datatype:"json" //can be omitted if json.
    save: {
        "insert":"data/data_insert.php",
        "update":"data/data_update.php",
        "delete":"data/data_delete.php"
    }
});

Here's a working example calling save on reordering (check the source code, and POST requests which calls datatable_order_save.php).

Or you can use onAfterEditStop combined with some ajax post, which should allow you to ignore if the update failed.

on: {
    onAfterEditStop: function(state, editor, ignoreUpdate){
        if(state.value != state.old){
            // some $ajax() post to update values
        }  
    }
}

I hope this helps.

Nick De Beer
  • 5,232
  • 6
  • 35
  • 50