hide grid when no rows exists

Questionshide grid when no rows exists
Wing Kam asked 3 years ago


is there a way to hide or not show the grid when there are no rows?

there's 2 grids on one page and user will select a row from table 1. That row will appear on table 2. However, at the beginning, table 2 will be empty so I want to hide it for a cleaner ui and less confusing.


5 Answers
Abu Ghufran answered 3 years ago

If you are using master detail grid,

1) Set detail grid in a div with display none: e.g.
<div id="grid2" style="display:none">$out2</div>

2) you can set following in master grid options:
$opt["onSelectRow"] = "function(){ $('#grid2').show(); }";

The detail grid will be initially hidden and when you select row of master grid, it will show that div.

Wing Kam answered 3 years ago

is there php code that I can check if the query returned any rows:

$g->select_command = "SELECT *
FROM invoices where id = $id;

is there a $g["rowcount"] to check?


Abu Ghufran answered 3 years ago

It's not doable with PHP. Grid generates the structure (toolbar etc) no first request, and load data on second ajax request.
Instead of master grid 'onSelectRow' you can connect event on list2 loadComplete,


$opt["loadComplete"] = "function(){ if (jQuery('#list2').jqGrid('getGridParam','records') > 0) $('#grid2_div').show(); }";

Sarino answered 3 years ago

Doesnt work! undefined var..

Abu Ghufran answered 3 years ago


The above JS code was just to give an idea.
I've not executed it. You need to debug yourself.

If you still think it is not workable, please send me your implementation along with screenshot for review at [email protected]

Your Answer

2 + 14 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?