jsGrid: как отложить обновление сетки до завершения обратного вызова? - PullRequest
0 голосов
/ 25 ноября 2018

Я использую js-grid для выполнения встроенных правок.Я использую обратные вызовы onItemInserting, onItemUpdating и onItemDeleting для выполнения вызовов AJAX для выполнения операций INSERT, UPDATE и DELETE на стороне сервера соответственно.Однако проблема заключается в том, что обновления на стороне клиента выполняются до выполнения обратных вызовов AJAX-вызовов.В результате обновления на стороне клиента происходят независимо от результата работы на стороне сервера.

Вот частичный код моего заявления:

   function displayConfigTable(config) {

        let parameters = {
            configName: config
        };

    $.getJSON("/configure", parameters, function(data, textStatus, jqXHR) {

       displayGrid(config, data);
    });

   }

   function onUpdateCallback({
    grid,                // grid instance
    row,                 // updating row jQuery element
    item,                // updating item
    itemIndex,           // updating item index
    previousItem,        // shallow copy (not deep copy) of item before editing
}) {
    //TODO:

}


function onDeleteCallback({
    grid,                // grid instance
    row,                 // deleting row jQuery element
    item,                // deleting item
    itemIndex,           // deleting item index
}) {
    //TODO:

}

function onInsertCallback({grid,item}) {
    var config = grid.configName;

    var data = {
        configName: grid.configName,
        item: item
    };

    $.ajax({
        type: 'POST',
        contentType: 'application/json',
        url: '/updateConfig',
        dataType : 'json',
        data : JSON.stringify(data),
        success : function(result) {
    alert(result);

    **//This is where I want the client-side update to happen to the grid**

    },error : function(result){
           console.log(result);

           **//this is where I want to cancel the client side update to grid**
        }
    });

   }



   function displayGrid(config,data) {

       var fields = [];
      switch(config) {
           case "category":
                fields =  [
            {name: "Id",visible:false,width:0},
            { name: "Name", type: "text", width: 250, validate: "required" },
            { type: "control" }]

               break;
            default:
                break;
       }

    $("#jsGrid").jsGrid({
        width: "100%",
        height: "auto",

        inserting: true,
        editing: true,
        sorting: true,
        paging: false,

        data: data,
        fields: fields,
        configName:config,
        onItemInserting:onInsertCallback,
        onItemUpdating:onUpdateCallback,
        onItemDeleting:onDeleteCallback
    });

   }
...