Adjust the height automatically in extjs hbox layout with this quick guide

When I try to dynamically set data in this layout, the layout doesn't resize properly and the final result looks like this.

This is the code I'm currently using:

win = Ext.create('widget.window', {
      title: 'Layout Window',
      closable: true,
      closeAction: 'hide',
      width: 750,
      height: 500,
      layout: 'fit',
      animCollapse: true,
      bodyPadding: 5,

      items: [{
                xtype: 'container',
                layout: 'hbox',
                align: 'stretch',
                items: [{
                          xtype: 'fieldset',
                          flex:1,
                          title: 'Details',
                          margins:'0 5 0 0',
                          layout: 'anchor',                          
                          autoHeight: true,
                          items: [{
                                    xtype: 'displayfield',
                                    fieldLabel: 'Name',
                                    name: 'customer_name',
                                    id: 'customer_name',
                                    width: 300
                                },{
                                    xtype: 'displayfield',
                                    fieldLabel: 'ID Card',
                                    id: 'customer_id',
                                    name: 'customer_id',
                                    width: 300
                                },{
                                    xtype: 'displayfield',
                                    fieldLabel: 'Address',
                                    name: 'address',
                                    id: 'address',
                                    width: 300
                                }]                        
                      },{
                          xtype: 'fieldset',
                          title: 'Details',
                          margins:'0 0 5 0',
                          flex:1,
                          layout: 'anchor',
                          autoHeight: true,
                          items: [{
                                    xtype: 'textfield',
                                    labelWidth: 120,
                                    fieldLabel: 'invoice',
                                    anchor: '98%',
                                    name: 'invoice_number',
                                    id: 'invoice_number',
                                    allowBlank: false,
                                    readOnly: true
                                },{
                                    xtype: 'textfield',
                                    labelWidth: 120,
                                    fieldLabel: 'Payment Amount',
                                    anchor: '98%',
                                    name: 'payment_amount',
                                    id: 'payment_amount',
                                    allowBlank: false
                                },{
                                    xtype: 'button',
                                    id: 'test'

                                    }]                        
                      }]                        
             }]


}).show();

I've used the above code snippet to set data for display fields as a test.

Ext.getCmp('test').on('click', function(){
    Ext.getCmp('customer_name').setValue('customer name customer_name customer_name customer_name');
    Ext.getCmp('customer_id').setValue('855');
    Ext.getCmp('address').setValue('some text, some text, some text, some text');
});

Any suggestions on how to resolve this issue would be greatly appreciated.

Warm Regards

Answer №1

Discover a simple trick to automatically expand the fieldset on the left based on content length:

After setting the content of the display fieldset, add this line of code:

win.query('fieldset')[0].setHeight('auto');

Here's an example without much modification: jsfiddle

(query is a method available globally to all components inheriting from Ext.Component, allowing you to query items like CSS selectors)

Additional Information

Key points to consider:

  1. When using align:'stretch', you cannot directly configure it with the component. Follow this approach instead:

    Ext.create('Ext.panel.Panel', {
        layout: {
            type: 'hbox',
            align: 'stretch'
        },
        items: [...]
    });
    

    Take a look at this testing demo here. The first window behaves as expected, while the second and third windows fail to stretch the panels.

  2. Starting from ExtJS 4, autoHeight has been removed from the configurations. You can use setHeight('auto') manually for achieving auto height.

UPDATE

It appears that using the column layout can produce the same effect without needing to use setHeight('auto'). Check out the fiddle here.

Cheers!

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

The visibility of the Google +1 button is lost during the partial postback process in ASP.NET

When trying to implement the Google Plus One button using AddThis on one of our localized pages, we encountered a strange issue. Despite retrieving data from the backend (let's assume a database), the plus button was not loading during an AJAX based p ...

Clicking on the checkbox will remove the selected text within the contenteditable div

My objective is to create a custom text editor with basic functionalities such as bold, italic, underline, and paragraph styling only. The purpose of this project is for studying purposes. The main challenge I am facing is avoiding color-based interaction ...

What is the alternative in HTML 5 to using the rules attribute for a table element?

Upon applying the rules attribute to this table element <table id="data" style="margin-top: 10px;border: 1px solid black; width:100%" rules="all"> An advisory message is displayed: The use of attribute (rules) is outdated and discouraged in HTML ...

What is the best way to evenly distribute input elements horizontally within the parent container?

I am working on a layout with five select inputs that I want to arrange horizontally within the parent div. However, the current code setup is not achieving the desired layout: <div id="divtable"> <select class="abc"></select> ...

Update the hidden input's value by the ZIP code entered

I'm currently working on setting up arrays for specific regions and then comparing them to the zip code entered in order to designate the value of a hidden field (which signifies the region). No matter what I input, it always seems to result in "Not F ...

The default setting for my bootstrap modal is displayed, not hidden

Is there a way to make my bootstrap model hidden by default and only visible when I click on a link? I'm new to web development and would appreciate any help. tst.html <!DOCTYPE html> <html lang="english"> <head> < ...

Update your mappings for the city of Istanbul when utilizing both TypeScript and Babel

Currently, I am facing the challenge of generating code coverage for my TypeScript project using remap Istanbul. The issue arises due to the usage of async/await in my code, which TypeScript cannot transpile into ES5 directly. To circumvent this limitation ...

Dim the entire screen within an ASP: UpdateProgress tag

As I develop my ASP.Net web page, the challenge of loading a significant amount of data in up to 60 seconds arises. I want the user to be informed that the process may take some time. My solution is to dim the screen slightly and display "Loading, please w ...

What is the most efficient way to retrieve the current user's ID within Loopback?

Given the instability and deprecation of loopback.getCurrentContext(), what strategies can I use to accurately identify users when they interact with API endpoints? Is it feasible to include the token ID in the request payload for verification purposes? H ...

Revert button design to default after second click

Looking for some assistance here. I have a button that toggles between displaying and hiding information. When the information is displayed, it should have one style, and when it's hidden, it should have another. Currently, I'm able to change the ...

Transferring information through AJAX to the current page using a foreach loop in Laravel 5

As a newcomer to ajax and laravel 5, I am eager to learn how to pass data with ajax to populate a foreach loop in laravel 5 on the same page. <div class="row" style="margin:3% 0px 0px 0px"> @foreach($warung_has_kategoriwarungs['i want pass ...

The AJAX call to an Express server is not sending any data

Recently, I developed a task management application called the "Task Tracker." The main functionality of this app is to use AJAX requests to communicate with an Express server. When a user enters a task in the input field, the data is supposed to be sent t ...

JavaScript exporting data to Excel and populating the top row with column

My code successfully exports a file via Excel without any errors. However, the issue I'm facing is that the exported Excel file contains a lot of unnecessary spaces. The problem is highlighted in the image provided: data from row 123 should be in col ...

Adding a dynamically generated list to the HTML DOM using AngularJS

I'm encountering an issue with my AngularJS function. It's supposed to dynamically add a list element to a div in the DOM using ng-repeat to iterate over objects from a list. The objects in the list have properties that I need to display. Here i ...

The screen reader is only able to detect the JQuery dialog box located at the bottom of the page

I am facing an issue with three jQuery dialog boxes on my website. Two of them work perfectly fine, where a screen reader reads the content as soon as they open. However, the third one, named surveyDialog, is only read at the very end after reading everyth ...

Tips on how to resize, position, and scale an object effectively using three.js

Recently delving into the world of three.js, I decided to experiment with importing models using the gltf loader. Upon loading a specific 3D model, my scene transformed to showcase a mesmerizing view, as depicted https://i.sstatic.net/l4jNy.png. However, ...

A guide on utilizing handlebars to display a JSON Array

I'm currently using Handlebars.js to display a repeating UI component... <div class="container-fluid article-container"> {{#each this}} <h1>{{header}}</h1> <h1>{{url}}</h1> <h1>{{body}}& ...

Is there a problem with AngularJS $state.go() not emitting $stateChangeSuccess?

In my scenario, I have controllers A and B located in different states. When I trigger $state.go('state_b');, Angular switches to state state_b and loads controller B. However, what surprises me is that I do not receive $stateChangeSuccess in my ...

The pure css overlay does not display correctly on Chrome

Could you take a look at the link provided below (just widen the result window a bit) and let me know why there are white lines on top and on the sides of the boxes when the hover overlay is fully loaded? Even when I use a background image for those divs, ...

Is it necessary for services in Domain Driven Design to have knowledge of other services, or should they be aware of multiple repositories

As I work on developing a backend application, my focus is on implementing the Domain Driven Design. However, there's a particular question I have regarding the data structure that requires some clarification. Database Configuration Users Id ( ...