Do action after render() method is completed

Kalinin picture Kalinin · Jun 3, 2011 · Viewed 11.7k times · Source

I need to do some action when render() method finished its work and appended all HTML elements to DOM. How to subscribe to onRenderEnds event (there is no such event)? Can I write my own event outside of slickgrid code and attach it to render() method?


There are some events "onScroll", "onViewportChanged" but they happened before render() finished (in some cases).


Update: I write formatter for column:

formatter: function(row, cell, value, columnDef, dataContext){
    return "<div class='operationList' data-my='" + myData + "'></div>";            
}

When grid rendered (applying my formatter) i need to go through all ".operationList" divs and convert them to other constructions (based on data-my attribute). I need to replace ".operationList" divs with a complex structure with event handlers.

Answer

magiconair picture magiconair · Nov 4, 2011

To answer on my own comment I've come up with the following hack. It may not be pretty but it seems to work.

Add the following line to the render() method just below renderRows(rendered);

function render() {
    ...
    renderRows(rendered);
    trigger(self.onRenderCompleted, {}); // fire when rendering is done
    ...
}

Add a new event handler to the public API:

"onRenderCompleted":            new Slick.Event(),

Bind to the new event in your code:

grid.onRenderCompleted.subscribe(function() {
    console.log('onRenderCompleted');
});