Hide show Grid from within script

QuestionsHide show Grid from within script
Glenn asked 4 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.

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;
// the below are just guesses
if(hidegrid == true)
$('#list1').jqGrid('setGridState', 'hidden');
$('#list1').jqGrid('setGridState', 'visible');

3 Answers
Abu Ghufran answered 4 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 4 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() {…}"
Will using loadComplete in this way cause any issues?


Abu Ghufran answered 4 years ago

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

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

Old convention is also supported:

$e["js_on_load_complete"] = array("do_onload", null, true);

Your Answer

3 + 13 =

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 / 5. Vote count:

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

Let us improve this post!