Reputation: 814
I would like to know if there is any way to get html representation of progressbar before it's rendered anywhere?
I need to render progressbar in a grid. As for now I use custom renderer for progress column:
renderer: function( value, metaData, record, rowIndex, colIndex, store ) {
var id = Ext.id();
(function(){
var progress = new Ext.ProgressBar({
renderTo: id,
value: progress_value
});
}).defer(50);
return '<div id="'+ id + '"></div>';
}
But it doesn't look user friendly, because progressbars render after grid has been rendered.
I think that it's possible to create custom progressbar with this functionality as one can see template source code that is rendered into html, but it's not so elegant I think.
The best thing would be create function like this, I think:
var generateRenderer = (function(){
var pb = new Ext.ProgressBar();
return function( progress_value ){
pb.updateValue( progress_value );
return pb.htmlRepresentationFunction();
}
})();
Where htmlRepresentationFunction()
is the function that returns html represetation (as obvious from it's name). And then use generateRenderer()
function in custom renderer.
Upvotes: 0
Views: 1182
Reputation: 814
As for now I've rewritten the code this way:
progressBarHtmlGenerator: (function(){
var width = progress_width,
cls = 'x-progress', // it's default class from ext.js
tpl = new Ext.Template( // this template is from ProgressBar.js in ext.js
'<div class="{cls}-wrap">',
'<div class="{cls}-inner">',
'<div class="{cls}-bar" style="width: {barWidth}px">',
'<div class="{cls}-text">',
'<div>{text}</div>',
'</div>',
'</div>',
'<div class="{cls}-text {cls}-text-back">',
'<div>{textBack}</div>',
'</div>',
'</div>',
'</div>'
);
return function(value, text, textBack){
return tpl.apply({
cls: cls,
barWidth: value*width || 0,
text: text || ' ',
textBack: textBack || ' '
})
}
})()
This template is from ProgressBar.js. And then I use this function in my custom renderer like this:
renderer: function( value, metaData, record, rowIndex, colIndex, store ) {
var value = progress_value;
return this.progressBarHtmlGenerator(value);
}.createDelegate(this)
So as I don't need animation it works, but still I hope there is some way much more elegant than this one.
Upvotes: 2