e4rthdog
e4rthdog

Reputation: 5223

Slickgrid update not consistent

My slick grid setup:

var records = [];
    var grid;
    var columns = [
        { id: "ServerName", name: "Server Name", field: "ServerName" },
        { id: "DVCurrent", name: "DV Current", field: "DVCurrent", editor: Slick.Editors.LongText },
        { id: "DVLast", name: "DV Last", field: "DVLast" },
        { id: "PYCurrent", name: "PY Current", field: "PYCurrent", editor: Slick.Editors.LongText },
        { id: "PYLast", name: "PY Last", field: "PYLast" },
        { id: "PDCurrent", name: "PD Current", field: "PDCurrent", editor: Slick.Editors.LongText },
        { id: "PDLast", name: "PD Last", field: "PDLast" }
    ];

    var options = {
        enableCellNavigation: true,
        enableColumnReorder: false,
        forceFitColumns: true,
        autoEdit: false,
        editable: true
    };

And the creation of the grid:

grid = new Slick.Grid("#myGrid", records, columns, options);

The function that gets the data from my MVC controller:

function GetRecords() {
        $.ajax({
            url: '@VirtualPathUtility.ToAbsolute("~/Home/GetRecords")',
            dataType: 'json',
            type: 'GET',
            success: function (data) {
                records = data;
                grid.setData(records);
                grid.invalidate();
            }
        });
    }

Everything goes well when the page loads. The data are fetched. the problm occurs when i click the save button and i want the grid to update again:

$('#btnSave').click(function () {
            $.ajax({
                url: '@VirtualPathUtility.ToAbsolute("~/Home/UpdateAllRecords")',
                dataType: 'json',
                contentType: "application/json",
                type: 'POST',
                data: JSON.stringify(grid.getData()),
                success: GetRecords
            });
        });

It simply doesnt do anything. the action completes successfully on serverside, but it does not refresh, like the GetRecords never run. No console errors.

If i reload the page the updated data are being fetched.

Upvotes: 0

Views: 93

Answers (1)

ghiscoding
ghiscoding

Reputation: 13194

You are probably missing this piece:

// Refresh the new data rendered 
grid1.updateRowCount();
grid1.render();

if that does not work, you can try having your save in async:false, you should check the result of your new dataset with firebug. Hope that helps..

Upvotes: 1

Related Questions