Search code examples
extjsgridrenderer

ExtJS 4: Grid Column Renderer Old Value


I have a grid that is reconfigure (referesh data) every 10 seconds (with AJAX). So the renderer function calls every 10 second and we have Value of current cell.

How can I compare value of current data with old data? Or simply, how can I get the old data in renderer function?

If we can not access old data, is there another solution to handle this?

Thank you in Advance


Solution

  • Once the store is loaded there's no way to get the old data. One thing you can do is listen to the beforeload event on the store & cache the old data:

    var oldData;
    myStore.on('beforeload', function() {
        oldData = myStore.getRange(); // Grabs an array of all current records
    });
    

    From here, the renderer will pass in the row index as one of the arguments, so you can just do a comparison:

    renderer: function(v, meta, rec, rowIndex) {
        var oldRec = oldData[rowIndex];
        // do your comparison
    }
    

    You'll also need to handle the case of the first load where there will be no oldData.