Retrieve the HTML representation of a progress bar in Ext JS 3.4 prior to its rendering

Is it possible to obtain the HTML representation of a progress bar before it is rendered anywhere?

I am currently using a custom renderer for rendering a progress column in a grid:

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>';
            }

However, this approach is not very user-friendly as the progress bars are rendered after the grid has been rendered.

I believe it might be achievable to create a custom progress bar with this feature by examining the template source code that is transformed into HTML. Although I consider this method less elegant.

The ideal solution would involve creating a function like the following:

var generateRenderer = (function(){
        var pb = new Ext.ProgressBar();
        return function( progress_value ){
            pb.updateValue( progress_value );
            return pb.htmlRepresentationFunction();
        }
    })();

Where htmlRepresentationFunction() generates the HTML representation and then incorporating the generateRenderer() function within the custom renderer.

Answer №1

After some revisions, the code now looks like this:

progressBarHtmlGenerator: (function(){
    var width = progress_width,
        cls = 'x-progress', // default class from ext.js
        tpl = new Ext.Template( // template taken 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 || '&#160;',
            textBack: textBack || '&#160;'
        })
    }
})()

The above template originates from ProgressBar.js and is utilized in a custom renderer as follows:

renderer: function( value, metaData, record, rowIndex, colIndex, store ) {
                var value = progress_value;
                return this.progressBarHtmlGenerator(value);
            }.createDelegate(this)

Although currently functional without animation, I am still exploring more elegant solutions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to change the response URL in an AJAX function?

I have a function using ajax that redirects to the response from a specified URL upon success: document.getElementById("button1").addEventListener("click", function (e) { e.preventDefault(); $.ajax({ url: 'http://localhost:8080/someLo ...

Replace the image with text inside an anchor when the anchor is being hovered

I want a logo (we'll call it .item-logo) to be shown inside a circle when not being hovered over, but when you hover over the container, the date should be displayed. Here is the HTML code: <div id="main-content" class="container animated"> ...

Navigate the div with arrow keys

Looking for an answer similar to this SO post on moving a div with arrow keys, could a simple and clear 'no' be sufficient: Is it possible to turn an overflowing div into a "default scroll target" that responds to arrow-up/down/page-down/space k ...

Determining where to implement the API display logic - on the server side or

Currently, I am in the process of restructuring an API that deals with user profiles stored in one table and profile images in another. The current setup involves querying the profiles table first and then looping through the images table to gather the ass ...

Element was removed upon clicking only once

Can anyone help me figure out why the behavior of .remove() with $postNav.remove(); is different here? When you click on "I'm a tag" for the first time, both the <li> and <ol> are deleted as expected. However, on the second click, only the ...

Data manipulation with Next.js

_APP.JS function MyApp({ Component, pageProps }) { let primary = 'darkMode_Primary'; let secondary = 'darkMode_Secondary' return ( <Layout primary_super={primary} secondary_super={secondary}> <Component {...page ...

There seems to be a problem with playing a UI video, but interestingly it functions

I am facing an issue with playing MP4 (HD) videos on the UI that I receive from the Django backend. My setup involves using normal Javascript on the frontend and Django on the backend. Here is a snippet of the backend code: file = FileWrapper(open(path, &a ...

The Material UI Rating Component is malfunctioning and showing an incorrect value

I'm currently working on a component loop that takes in async data. Everything is rendering properly except for the first component, where the Rating component isn't displaying its value correctly (it just shows 0 stars). Here's the code: & ...

Exploring layered data through specific properties

Imagine a scenario where I have an array filled with data. Each element in this array is an object that could contain: an id some additional data a property (let's name it sub) which may hold an array of objects with the same properties (including t ...

Having trouble with my OpenAI API key not functioning properly within my React application

I've been struggling to implement a chatbot feature into my react app, specifically with generating an LLM-powered response. Despite going through documentation and tutorials, I haven't been successful in resolving the issue. My attempts involve ...

What is causing the Access-Control-Allow-Origin error when using axios?

I have a simple axios code snippet: axios.get(GEO_IP) .then(res => res) .catch(err => err); In addition, I have configured some default settings for axios: axios.defaults.headers["content-type"] = "application/json"; axios.defaults.headers.common. ...

Caution: Anticipated the server's HTML to include a corresponding <body> within a <div> tag

Upon checking the console, I noticed a warning message appearing. I am puzzled as to why this is happening since I have two matching <body> tags in my index.js file. The complete warning message reads: Warning: Expected server HTML to contain a matc ...

Ways to display a US map using d3.js with state names positioned outside each state and pointing towards it

Currently, I am working with d3.js and d3-geo to create a map of the USA. My goal is to display the names of some states inside the state boundaries itself, while others should have their names positioned outside the map with lines pointing to the correspo ...

In JavaScript, a prompt is used to request the user to input a CSS property. If the input is incorrect,

Implement a while loop that continuously prompts the user to enter a color. If the color entered matches a CSS property such as blue, red, or #000000: The background will change accordingly, but if the user enters an incorrect color, a message will be dis ...

Best methods for deleting an element's attribute or style attribute

Imagine this snippet of CSS code: .notif-icon { display: inline-block; } In my HTML, I have the following element which starts off hidden by overriding the display property of the notif-icon class: <span id="error" class="notif-icon& ...

Having trouble executing the yarn command for clasp login

Issue with running yarn clasp login I am not very proficient in English, so please bear with me. 8> yarn clasp login yarn run v1.22.22 $ C:\Users\myname\Desktop\個人開発プロジェクト\clasp-240418\node_modu ...

Angular & Loopback: The function User.login is not recognized

Today, I encountered an error while attempting to execute the Login function in Ionic. An error message popped up stating: TypeError: User.login is not a function (found in controller.js). Here's a snippet from my controller.js : angular.module(&ap ...

How to Use Javascript to Listen for Events on a Different Web Page

Is it possible to open a popup using window.open and then subscribe to page events (such as onload) of the popup from the opener? I am looking for a method in my parent page (opener) that will execute when the popup's onload or ready event fires. Can ...

Having trouble loading the .php file with my Ajax request

Attempting to retrieve data from the postcode.php file and display it in a #postcodeList div, but encountering issues as nothing happens. Upon inspecting the postcode.php file, it seems to be outputting all the correct information. var loadicecream = do ...

Refreshing the page causes Material UI Button to revert to default styling

My question regarding the Material UI Button losing styling after a page refresh (link: Material UI Button loses Styling after page refresh) went unanswered, so I am reposting with a CodeSandbox included for reference: https://codesandbox.io/s/bold-resonan ...