Kendo Grid: saving state in columnReorder event

I have created some code to save and restore the order of the columns, and it will also work with resizing if I can force it to save the necessary data. It seems that when the "columnReorder" event occurs, the new column order has not yet been saved - therefore, despite the fact that the function of saving and restoring the column works, it is one step back. Does anyone know how to get β€œnew” column information or capture an event after a reorder has been made? Here is the part that does the magic ...

    var colCook = getCookieColumns();

    //setup user columns or cookie columns as appropriate
    $("#disputesGrid").kendoGrid({
        dataSource: myDataSource,
        columns: (colCook != null) ? JSON.parse(colCook) : {default column values},
        pageable: {
            refresh: true,
            pageSizes: [10, 25, 50, 100],
            buttonCount: 10,
            input: true
        },
        reorderable: true,
        columnReorder: function (e) { saveColumnsCookie(); },
        sortable: true,
        resizable: true,
        selectable: "multiple row"
    });
}

function getCookieColumns() {
    var cookiesArray = document.cookie.split(';');
    for (var i = 0; i < cookiesArray.length; i++) {
        var c = cookiesArray[i].trim();
        if (c.indexOf("DisputeGridViewColumns=") == 0) return c.substring(23, c.length);
    }
    return null;
}

function saveColumnsCookie() {
    //saves the current column information into a cookie
    try {
        var d = new Date();
        d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toGMTString();
        document.cookie = "DisputeGridViewColumns=" + kendo.stringify($("#disputesGrid").data("kendoGrid").columns) + "; " + expires;
    } catch (x) { 
        //it fails when the grid isn't initialized - we can just ignore that
    }
}

Note: the new column order does not seem to be in the "e" event, but what is a reasonable place, right?

+4
1

e.column ( ), e.newIndex ( ) e.oldIndex ( ), . , , setTimeout:

columnReorder: function(e) {
    var that = this;
    setTimeout(function() {
        console.log(kendo.stringify(that.columns));
    }, 5);
}

()

+10

All Articles