The renderer
function in ExtJS is merely a function that, for the given column, is called for every row in the grid. The output of this function is used to render the text inside that particular cell of the grid.
If what you want to do is allow to dynamically add columns to the grid, with the new columns having the value of month "decremented by 1" compared to the previous month, what you have to do is to build a renderer that has some specific additional parameter attached to it, which you can do for example by using JavaScript's bind
method. Every time you add the column, you'll create an instance of such renderer passing a different value.
The following StackOverflow post will give you a hint on how to make columns dynamic:
How to dynamically add columns for Grid ExtJs
As for the renderer
function and its usage, it goes more or less as follows:
function customRenderer(value, cell, record) {
var result = value - this.index;
return value + " - " + this.index + ' = ' + result;
}
var columns = [];
for(var i = 0; i < 10; i++) {
var column = {};
column.dataIndex = 'column' + i;
column.text = 'Column ' + i;
column.renderer = customRenderer.bind({ index: i, column: column });
}
reconfigureExtJSColumnsPseudoFunction(columns);
The above code, which you will of course have to tune based on your needs, takes the customRenderer
function and changes its scope, thus allowing you to provide it with additional context. Each iteration in the for
loop will create a new "version" of that function running in a different scope (through the bind
method) thus ensuring that each column will receive a different value for the index
property, allowing you to dynamically change the amount you will then subtract based on the column index itself.