Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Autowidth with jquery Tabs
08/10/2009
14:21
Avatar
sanchitos
Member
Members
Forum Posts: 14
Member Since:
05/10/2009
sp_UserOfflineSmall Offline

Here's the thing:

I have two tabs on a page with jqgrids on each one.

Both jqgrids have autowidth property set, the problem is when page loads the first grid is adjusted to the size of the container but when i clicked the second tab the second grid is not adjusting to the size of the container.

Image Enlarger

Code:

   jQuery(document).ready(function() {
        jQuery(NOMBRE_GRID).jqGrid({
            url: '/Idiomas/DatosGrid/',
            datatype: 'json',
            mtype: 'GET',
            height: 'auto',
            multiselect: true,
           
            autowidth: true,           
            colNames: ['Id',  'Nombre'],
            colModel: [
                      { name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
                          formatter: 'showlink', formatoptions: { baseLinkUrl: '/Idiomas/', showAction: 'Edit', addParam: '' }
                      },
                      { name: 'nombre', index: 'nombre', width: 100, align: 'left' }
                  ],
            pager: jQuery(NOMBRE_AREA_PAGINACION),
            rowNum: tamanoPagina,
            rowList: [5, 10, 15, 20],
            sortname: 'nombre',
            sortorder: "asc",
            viewrecords: true,           
            caption: 'Idiomas'
        }).navGrid(NOMBRE_AREA_PAGINACION, { edit: false, add: false, del: false, refresh: false, search: false });
    });
       
    jQuery(document).ready(function() {
        jQuery(NOMBRE_GRID_SELECCIONADOS).jqGrid({
            url: '/Idiomas/DatosGrid/',
            datatype: 'json',
            mtype: 'GET',
            height: 'auto',
            multiselect: true,
           
            autowidth: true,           
            colNames: ['Id',  'Nombre'],
            colModel: [
                      { name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
                          formatter: 'showlink', formatoptions: { baseLinkUrl: '/Idiomas/', showAction: 'Edit', addParam: '' }
                      },
                      { name: 'nombre', index: 'nombre', width: 100, align: 'left' }
                  ],
            sortname: 'nombre',
            sortorder: "asc",
            viewrecords: true,           
            caption: 'Idiomas'
        });
     });

Html:

<div id="tabs">   
        <ul>
            <li><a href="#tab-1">TAB1</a></li>
            <li><a href="#tab-2">TAB2</a></li></ul>
        <div id="tab-1">
           <table id="Integra2_Lista" cellpadding="0" cellspacing="0">
            </table>
            <div id="Integra2_Paginacion" class="scroll" style="text-align: center;">
            </div>
        </div>
        <div id="tab-2">
            <table id="Integra2_SeleccionadosLista" cellpadding="0" cellspacing="0">
            </table>

        </div>
    </div>

Thank you guys, any guess, what might be happening, how can i fix it or if it's just a normal behavior.

08/10/2009
16:26
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

The default for tabs is that hidden tabs get “display:none”. The result of that is that the container size is reported as zero.

So when the grid in the hidden container initializes, /its/ container has zero size, and it sizes itself accordingly.

You have a couple of options:

 - you can add your own css to make the hidden tab content visible, but offscreen:

.ui-tabs .ui-tabs-hide {
    position: absolute;
    left:-10000px;
 }

- you can defer creating the grids until their tabs are selected (use the tabselect event).

$(mytab).tabs({selected:-1,select:mygridcreatefn});

$(mytab).tabs(”select”, 0);

Where mygridcreatefn creates the grid for the selected tab if it doesnt already exist.

Mark

21/10/2009
21:18
Avatar
michael
Member
Members
Forum Posts: 12
Member Since:
01/10/2009
sp_UserOfflineSmall Offline

Mark, that is very helpful. Thanks.

22/10/2009
15:28
Avatar
jmav
Member
Members
Forum Posts: 34
Member Since:
16/10/2009
sp_UserOfflineSmall Offline

I better to create grid when the tab is selected.

Use tabs event: http://docs.jquery.com/UI/Tabs.....event-show

Resize functions that i made

http://www.trirand.com/blog/?p.....id/#p10996

You can attach it on the same tab event.

22/10/2009
20:38
Avatar
michael
Member
Members
Forum Posts: 12
Member Since:
01/10/2009
sp_UserOfflineSmall Offline

From my experience creating the grid when a tab is selected creates multiple duplicated navGrid buttons when the tab is reselected. Anyone else experiencing this?

23/10/2009
00:10
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

It'll do that if you create it every time the tab is selected.

I recommend creating it once, the first time its selected, and never again...

Mark

26/10/2009
01:26
Avatar
michael
Member
Members
Forum Posts: 12
Member Since:
01/10/2009
sp_UserOfflineSmall Offline

Thanks again Mark. Any tip of a specific event or function for this?

26/10/2009
09:40
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Well, use the tabselect event, and keep a flag to say whether or not you've created the grid...

Mark

27/10/2009
02:28
Avatar
michael
Member
Members
Forum Posts: 12
Member Since:
01/10/2009
sp_UserOfflineSmall Offline

Got that. Thanks!

07/12/2009
17:21
Avatar
pvdemael
Guest
Guests

Hi markw65 and others,

Do you accidentally have an example of this?

I've created a page with 2 tabs, one with a grid, the other with a form.

When the page is loaded, I run a function to create the tabs and grid. The grid is shown first and is ok. When I click on the Form tab, the form shows. Going back to the Grid tab, I does not show anything. I am probably making a very stupid mistake.

I tried another solution from the forum but #volunteer_grid does not exist, looking in the generated html, I see grod_volunteer_grid. What is this about, am I missing something.

Off topic, sorry for that, I was able to do grid resizing with window resizing, how do I do that with jquery tabs?

function volunteer_tabs_and_grid() {

    var grid_exists=0;

    $("#navmenu").tabs({
        load: function(event, ui) {
                 if (ui.index==0)  { // only show grid in first tab
                    if (grid_exists)  {
                        alert('grid exists'); // test if this works, it does, how can I show the grid then?
                    }
                    else  {
                        volunteer_grid();
                        grid_exists = 1;
                    }
                }
                else {
                     // do nothing for now
                }

})

    $("#navmenu").tabs('add', 'index.php/volunteer/show_list', 'Lijst');
    $("#navmenu").tabs('add', 'index.php/volunteer/show_form', 'Form');
    $("#navmenu").tabs('option', 'ajaxOptions', { type: "POST" });

}

08/12/2009
18:05
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I think the problem is how you construct your tabs. Also if the grid exists you should not do anything, the tabb UI just show this content. You can look into the demo how is this organized.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

09/12/2009
14:34
Avatar
pvdemael
Guest
Guests

Hi Tony,

Thanks for your answer. I am not a js and jquery specialist but am eager to learn.

I looked at the code of the demo site with FireBug as you suggested and I think I figured out what you do:

1) The main tab is created with an add event function defined (for closing tabs)

2) A treeGrid is created for the main menu with an associated url for every leaf of the tree (eg jsonex.html)

3) An onSelectRow event callback is created: On selection of a leaf of the treeGrid, the existence of the tab associated with the leaf is checked. If the tab does not exists, an ajax request is sent to the server which returns the html of the associated url. The html includes a script tag which defines the grid with the data.

This looks very simple and it works perfectly Wink.

This is my application:

I have a main menu in the left pane with. Just ordinary links, but prettified with jquery and ajax requests.

Each time a menu item is clicked, a tab navigation should show on top of the right pane with a grid in the first tab. Tabs can be added or removed by clicking on rows of the grid.

When another menu item is clicked, all existing tabs and grids should be removed to make place for a new tab and new grids.

Is it better to keep the main tab navigation and remove all tabs?

Should I keep the grids when another main menu item is clicked? I don't think so, as I want to empty the tabs on clicking a main menu item.

Is the grid completely removed if the tab is closed?

What am I doing wrong with my tab creation?

Could you please help me out with this one? What is the best way to do this in terms of architecture? I really want to avoid design flaws.

Thank you very much!

11/12/2009
14:15
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Also maybe you should look into the code connected with the tabs creation/removing again

If the tab is removed the grid is removed too, since the grid element is a child of the tab div.

Will try to help if you provide a link to the problem.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

22/12/2009
05:07
Avatar
Dmoney
Member
Members
Forum Posts: 8
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

Im using tabs as well except I've created a seperate file for my grid and I use the ajax option in jquery tabs to display the grid.  It works great except the autowidth is not working. The grid does not expand to fill the available space inside the tab.   I want to continue to load the grid with the ajax method b/c the data for the grid could possible change depending on user input in the other tabs or they may choose not to look at the grid at all. I've searched the forums here but have not found any solution to this.

10/05/2010
15:29
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

Hello,

I had the same problem sanchitos had and I tried solving it with what is explained here. However, I still have the same problem.

I am using jquery-ui tabs and a jqgrid in each tab.

Each grid has the autowidth property set to true in order to have the same width as the parent tab.

I am only creating a tab's grid on its first selection in order for the width calculation to work correctly.

However, only the first tab gets its jqgrid's width set correctly to the tab width.

Here is the code I use:

HTML:

<div id="tabs">
            <ul>
                <li><a href="#tab1">tab1</a></li>
                <li><a href="#tab2">tab2</a></li>
            </ul>
            <div id="tab1">
                <table id="grid1"></table>
                <div id="pager1"></div>
            </div>
            <div id="tab2">
                <br />
                <table id="grid2"></table>
                <div id="pager2"></div>
            </div>
</div>

JS:

$(document).ready(function() {
    grid1Created = false;
    grid2Created = false;

    $('#tabs').tabs
    (
        {
            selected:-1,
            select: function(event, ui)
                {
                   var selected = ui.index;
                    
                    if(selected == 0 && !grid1Created)
                    {
                        creategrid1();
                        grid1Created = true;
                    }
                    else if(selected == 1 && !grid2Created)
                    {
                        creategrid2();
                        grid2Created = true;
                    }
                }
        }
    );
    $('#tabs').tabs('select', 0);
});

Where creategrid1 and creategrid2 are the fonctions that create the grids.

The thing is the grids are created normally only on their tab's first selection, but only the first grid has a width equal to the tab width.

Both grids use the following parameters:

  • autowidth: true
  • shrinkToFit: false

I would really appreciate any help.

Thanks!

11/05/2010
12:48
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

I still can't figure it out. I have tried looking in the jqgrid code without success.

Any idea?

Thanks.

12/05/2010
14:18
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

Well, still the same problem whatever I try.

Is it possible that in the latest jqgrid release, the grid width calculation mecanism has changed?

This would explain why the jquery.tabs events trick is not working.

14/05/2010
14:54
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

I have changed the event I use from "select" to "show" and it works just fine!

Here is a code example:

$(document).ready(function() {

    var initialized = [false,false,false,false];

    $('#tabs').tabs
    (
        {
            show: function(event, ui)
                {
                    if(ui.index == 0 && !initialized[0])
                    {
                        creationGrid0();
                        initialized[0] = true;
                    }
                    else if(ui.index == 1 && !initialized[1])
                    {
                        creationGrid1();
                        initialized[1] = true;
                    }
                    else if(ui.index == 2 && !initialized[2])
                    {
                        creationGrid2();
                        initialized[2] = true;
                    }
                    else if(ui.index == 3 && !initialized[3])
                    {
                        creationGrid3();
                        initialized[3] = true;
                    }
                }
        }
    );
});

Hope this will help someone.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
57 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information