Hide show Grid from within script

QuestionsHide show Grid from within script
Glenn asked 9 years ago

I added an event that calls grid_load when setting up the grid.
If the status value is good I want the grid to be collapsed.
What is the call from within a script to collapse it.

<script>
function grid_load()
{
var grid = $('#list1');
var rowids = grid.getDataIDs();
var columnModels = grid.getGridParam().colModel;
var hidegrid = false;

// check each visible row
for (var i = 0; i < rowids.length; i++)
{
var rowid = rowids[i];
var data = grid.getRowData(rowid);

if (data.status == 'Good')
{
hidegrid = true;
break;
}
}
// the below are just guesses
if(hidegrid == true)
$('#list1').jqGrid('setGridState', 'hidden');
else
$('#list1').jqGrid('setGridState', 'visible');
}
</script>

3 Answers
Abu Ghufran answered 9 years ago

Your code looks fine.
To test further, you can comment out everything except:

$('#list1').jqGrid('setGridState', 'hidden');

It will collapse on grid load.

If it is not working as expected, try some debugging by putting alert() statements and check if all variables data are fetched correctly.

Glenn answered 9 years ago

Thanks Abu,
I was not calling it correctly.
It is working now.
I ended up putting it in
$agrid_options["loadComplete"] = "function grid_load() {…}"
$ogrid->set_options($agrid_options);
Will using loadComplete in this way cause any issues?

Glenn

Abu Ghufran answered 9 years ago

It should work too (with new build v.1.5.2+)

$opt["loadComplete"] = "function(ids) { do_onload(ids); }";
$grid->set_options($opt);

Old convention is also supported:

$e["js_on_load_complete"] = array("do_onload", null, true);
$grid->set_events($e);

Your Answer

15 + 7 =

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?