Friday, June 13, 2008

Tabbed Regions in Oracle Apex using Extjs

David from Scotland emailed asking how I implemented tabbed regions on my demo site.



It's actually very easy using Extjs.

Step 1 - Create a region template which uses static ids

<div id="#REGION_STATIC_ID#" class="tab-content">
<div class="x-fieldset-bwrap" style="padding:10px">
<div align="right" class="x-fieldset-tbar">#CLOSE##PREVIOUS##NEXT##DELETE##EDIT##CHANGE##CREATE##CREATE2##EXPAND##COPY##HELP#</div>
<div class="x-fieldset-body">
#BODY#
</div>
</div>
</div>


Step 2 - Create your report/form regions as usual, but assigning them a static id.

I tend to use tab1, tab2, ..., tabn - but that's a personal choice.

Step 3 - Add an opening div tag before the first tab region and a closing div tag after the last region.

<div id="pageTabs">
</div>

You can either create extra regions of type "html text" with no template,
or simply add the extra tags in your region header and region footer.

I use extra regions, so it's really obvious whats going on when I look at again in 6 months time.


When the page is generated the html will look like this:

<div id="pageTabs">
<div id="tab1" class="tab-content"> <!-- content --> </div>
<div id="tab2" class="tab-content"> <!-- content --> </div>

<!-- and so on -->

<div id="tabn" class="tab-content"> <!-- content --> </div>
</div>

Step 4 - Add the javascript magic

Here I'm showing 2 tabs, and usually include the script with the closing div tag.

<script type="text/javascript">
Ext.onReady(function(){
var tabs = new Ext.TabPanel({
cls: 'prism',
applyTo: 'pageTabs',
plain: true,
width: 795,
//height: 450,
autoHeight:true,
enableTabScroll:true,
autoScroll:true,
activeTab: 0,
deferredRender: false,
border: true,
defaults: {layout:'fit', autoScroll:true},
items:[
{contentEl:'tab1', title:'Create/Edit Customer'},
{contentEl:'tab2', title:'Existing Customers'}
]
});
});
</script>


The cls: 'prism' is a customisation I use to have a blue background for the tab panel.
I'll leave that for you to work out how I did that.

As usual, the documentation on tab panels goes into far more details.


Mark

11 comments:

Anonymous said...

Very Nice work.

David said...

Many thanks for that mark

Anonymous said...

Mark this is a sweet technique. I was hoping someone might put out the instructions on how it works. I am gonna try this soon. Thanks again!

David said...

Hi, I tried to integrate this simple solution but firebug gives me the following java script error

Ext is not defined
Ext.onReady(function(){

Do I have to put the script within the --> close tab /div tag?

I am using apex 3.0

thanks

Mark Lancaster said...

Hi David

"Ext is not defined" usually happens if you haven't included the ext libraries in your page template.

See my earlier post http://oracleinsights.blogspot.com/2008/02/integrating-ext-javascript-library-into.html for integration details

Meyer said...

Thank you for your informative blog. How do you link the report to display the form when the edit icon is selected on any row? Keep up the good work.

Mark Lancaster said...

Hi Meyer

I'm using standard Apex functionality for the edit icon.

The page is just a report region and a form region.
The report has a column link which calls the same page passing the customer_id.

e.g.

http://apex.oracle.com/pls/otn/f?p=200801:2005:4231872663693000::::P2005_CUSTOMER_ID:26546

Mark

Meyer said...

Mark,
Is it possible to have more than two tabs and then change the active tab with the column link as previously described, i.e. have a customer address report region on another tab and a customer address edit form on another region within the same tabpanel.
When the user selects an address from the report region then the address edit form should be displayed. This means the page will contain four tabs with two report and two form regions.
Thanks again.
Meyer

Mark Lancaster said...

Hi Meyer

Yes it is.

Refer to the doco on activeTab and setActiveTab.

You just need to work out your logic and generate the javascript.

Charles said...

I do appreciate your work and your samples of you interfacing APEX and JavaScript using Extjs. I am having a problem getting the "tabbed region" up and running. I have spent hours and hours working on it, but for some reason, I'm not connecting the dots.

I have followed your suggestions as closely as I could, but I am still unable to make it work.

I posted a question on the APEX forum in hopes of a solution, but so far, none quite yet. I am pasting the link to the thread, if you get a chance, could you take a look at it and see if you can offer some suggestions/help. I hate asking, but your solution is clearly the one for my application, and if only I could get this sample up and running, I would sign on full speed!

Look at the thread below, and please give me some advice.

Thanks,

Charles

http://forums.oracle.com/forums/thread.jspa?threadID=829375&tstart=0

vfdvgf said...

I think wow gold and world of warcraft gold