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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Before the AI Coding Agent Writes Code: Structuring Scattered Requirements With PARA
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Designing for Security
  • Mastering GitHub Copilot: Top 25 Metrics Redefining Developer Productivity

Trending

  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups
  • Deploying Small Language Models on Sovereign Cloud
  • Beyond @Transactional: Solving the Dual-Write Problem in Distributed Microservices
  • How to Format Articles for DZone

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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

By 
Loiane Groner
·
Aug. 24, 10 · News
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
49.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Before the AI Coding Agent Writes Code: Structuring Scattered Requirements With PARA
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Designing for Security
  • Mastering GitHub Copilot: Top 25 Metrics Redefining Developer Productivity

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook