DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Top Six React Development Tools
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • A React Frontend With Go/Gin/Gorm Backend in One Project

Trending

  • Top Six React Development Tools
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • A React Frontend With Go/Gin/Gorm Backend in One Project
  1. DZone
  2. Culture and Methodologies
  3. Agile
  4. How to resize an ExtJS Panel, Grid, Component on Window Resize without using Ext.Viewport

How to resize an ExtJS Panel, Grid, Component on Window Resize without using Ext.Viewport

Loiane Groner user avatar by
Loiane Groner
·
Aug. 24, 10 · News
Like (0)
Save
Tweet
Share
46.86K Views

Join the DZone community and get the full member experience.

Join For Free

This post will walk through how to resize an ExtJS Panel, Grid, Component on Window Resize without using Ext.Viewport.



Problem:

You have a legacy page and you want to change an html grid for an ExtJS DataGrid, because it has so many cool features. Or you have a page with some design and you are going to use only one ExtJS Component. In both cases, you also want to render your ExtJS Component to a specific DIV. Also, you want you component to be resized in case you resize the browser window.

How can you do that if resize a single component in an HTML page it is not the default behavior of an ExtJS Component (except if you use Ext.Viewport)?

Solution:

Condor (from ExtJS Community Support Team) developed a plugin that can do that for you.

I had to spend some time to understand how the plugin works, and I finally got it working as I wanted.

Well, I recommend you to spend some time reading this thread: http://www.sencha.com/forum/showthread.php?28318 (if you have any issues or questions, please publish it on the thread, so other members can give you the support you need).

Requirements to make the plugin work:

Your have to apply the following style to the DIV (the width is up to you, the other styles are mandatory, otherwise it will not work):

<div id="reportTabContent" style="overflow: hidden; position:absolute; width:98%;"></div>

If you have any border around your ExtJS component, you have to set a HEIGHT. And you will also have to set a height to your ExtJS component. In this case, autoHeight will not work. If you DO NOT have any border or other design on the ExtJS component side, you do not need to set height and you can use autoHeight. In my case, I put a border on the external DIV, so I have to set Height:

<div style="border:3px solid #000000; padding:1px; width:99%; height:500px;">

HTML code (all DIVs):

<div style="border:3px solid #000000; padding:1px; width:99%; height:500px;">
	<table>
	<tr>
	<td style="overflow: hidden; width:100%;">
		<div id="reportTabContent" style="overflow: hidden; position:absolute; width:98%;"></div>
	</td>
	</tr>
	</table>
</div>

And you need to add the plugin to the component (In this case, I’m using an ExtJS DataGrid):

var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: 'Company', width: 160, sortable: true, dataIndex: 'company'},
{header: 'Price', width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
{header: 'Change', width: 75, sortable: true, renderer: change, dataIndex: 'change'},
{header: '% Change', width: 75, sortable: true, renderer: pctChange, dataIndex: 'pctChange'},
{header: 'Last Updated', width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
stripeRows: true,
autoExpandColumn: 'company',
height: 490,
autoWidth:true,
title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
,viewConfig:{forceFit:true}
,renderTo: 'reportTabContent' // render the grid to the specified div in the page
,plugins: [new Ext.ux.FitToParent("reportTabContent")]
});

And done! Now you can resize the browser and the component will resize itself!

I tested it on Firefox, Chrome and IE6.

You can download my sample project from my GitHub: http://github.com/loiane/extjs-fit-to-parent

PS.: If you want to use the full browser window, use a Viewport.

Happy coding!

Design HTML Coding (social sciences) Requirement Internet Explorer 6 POST (HTTP) teams GitHub

Published at DZone with permission of Loiane Groner, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Top Six React Development Tools
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • A React Frontend With Go/Gin/Gorm Backend in One Project

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: