Search code examples
javascriptjsgrid

how can i bind custom remote data that change in success handler to Grid fields


I am using jsGrid in my project and i have problem with edit data from ajax to bind in JsGrid fields.

how can i bind that edited data to Grid fields in JsGrid for example:

loadData: function (item) {
                return $.ajax({
                    type: "POST",
                    url: "url.html?cmd=fill",
                    data: null,
                    dataType: "json",
                    success: function (data) {
                          var list=eval(data);
                           //this loop is for example
                           for(var i=0;i<list.length;i++)
                            { 
                               list[i].id=i+1;
                                //how to bind this list to Grid Fields
                            }
                    }
                });
            }

Solution

  • You should return a promise resolved with the data after processing:

    loadData: function (item) {
        var d = $.Deferred();    
    
        $.ajax({
            type: "POST",
            url: "url.html?cmd=fill",
            data: null,
            dataType: "json",
            success: function (data) {
                var list=eval(data);
                for(var i=0;i<list.length;i++)
                {
                    list[i].id=i+1;
                }
                d.resolve(list);
            }
        });
    
        return d.promise();
    }