Hide expand – Subgrid

QuestionsHide expand – Subgrid
Frederik asked 6 years ago

Hello, how can i hide the "+" button in a master grid when the subgrid have no rows?
I can use a master grid field to define when hide or show the "+" button ?

Thanks

7 Answers
Abu Ghufran answered 6 years ago

Hi,

1) Connect onload event with grid.

$opt["loadComplete"] = "function(){ do_onload(); }";

2) Write callback function to iterate the master rows for your condition in desired column, and remove the td of +/- sign.
for e.g. to remove + sign from gender = male …

<script>
function do_onload()
{
var grid = $("#list1");
var ids = grid.jqGrid('getDataIDs');
for (var i=0;i<ids.length;i++)
{
var id=ids[i];
if (grid.jqGrid('getCell',id,'gender') == 'male')
{
jQuery('tr#'+i+' td.ui-sgcollapsed').replaceWith('<td>');
}
}
}
</script>

Full source: subgrid.php
http://pastebin.com/DbLsHPrM

Frederik answered 6 years ago

Hello Abu, thanks for your reply!

I fix this line
jQuery('tr#'+i+' td.ui-sgcollapsed').replaceWith('<td>');
with
jQuery('tr#'+id+' td.ui-sgcollapsed').replaceWith('<td>');

and it works, thanks!

Abu Ghufran answered 6 years ago

Hello,

It is not recommended practice to load 2000+ records at a time.
It also consume too much of browser memory (due to js processing).

What i recommend is to load data on-demand, for e.g. when page is scrolled down, it would load next page. e.g.

$opt["scroll"]=true;
$g->set_options($opt);

Frederik answered 6 years ago

Hi Abu, with this method i'm having problems like long loading time on a 2000+ record table (like 3 minutes of loading vs 15sec without do_onload method).

Because the grid puts the "+" on every row (if exist or not a subgrid result row), this method will scan all rows and results very laggy.

So, can you provide me a method to filter the "+" button when the grid is building the rows?

Thanks!

Frederik answered 6 years ago

Hi Abu, thanks for your response.

I'm trying this options:

$g = new jqgrid();
$grid["rowNum"] = 150;
$grid["scroll"] = true;
$g->set_options($grid);

I'm scrolling down but it shows still 150 rows, so how it works?

Thanks

Frederik answered 6 years ago

I tried also $grid["rowNum"] = 0; and $grid["rowNum"] = 2000; and without specifying a rowNum but, but i can't see the scroll option in action.

thanks

Abu Ghufran answered 6 years ago

Set,

$grid["rowNum"] = 20;
$grid["scroll"] = true;
$g->set_options($grid);

This would load only 20 records and load more when scrolled.

Your Answer

5 + 15 =

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?