jeffery_the_wind
jeffery_the_wind

Reputation: 18228

How can the IDs of visible jqGrid grids be determined?

I have a page with severl jqGrids, but only one is visible at a time. I want a simple function to return which one is visible at any time. Is there some function like this, which would show which divs are visible:

$('div').each(function(){
    if($(this).is(':visible')){
        alert($(this).attr('id'));
    }
});

Is there something like this that can parse through all jqGrids on a page?

Thanks!

Upvotes: 1

Views: 1803

Answers (2)

Oleg
Oleg

Reputation: 221997

You need probably something like the following

$("table.ui-jqgrid-btable:visible").attr('id');

If no grid are on the table you will get undefined value. If more as one grid is visible you will get the id of the first one.

To have array of ids of all visible grids you can use the following code

var ids = $.map($("table.ui-jqgrid-btable:visible"), function(value) {
        return value.id;
    });
// now we have all ids in the array
alert(ids.join()); // display all as comma-separated

You can make the above code more safe with the test for grid expandos:

var ids = $.map($("table.ui-jqgrid-btable:visible"), function(value) {
        if (value.grid) { return value.id; }
    });
// now we have all ids in the array
alert(ids.join()); // display all as comma-separated

Upvotes: 3

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

As far as I have seen, All grids are wrapped with a div class ui-jqgrid. So try something like below,

$('div.ui-jqgrid:visible').each(function () {
   alert(this.id); //above would return the gview_<table_id> or gbox_<table_id> or 
                   //something_<table_id>
   alert($(this).find('.ui-jqgrid-btable').attr('id')); //should return table_id
});

Upvotes: 1

Related Questions