tags:

views:

222

answers:

2

I have a jqgrid that has a subgrid. How can I expand the subgrid without having to click on the plus sign?

I came across $("#jqgrid_id").expandSubGridRow(rowId); but am unsure which rowId to use to expand the subgrid.

Thanks.

+1  A: 

Use $("#jqgrid_id").expandSubGridRow(rowId); in the onSelectRow Event of the grid.

Something like this:

jQuery("#jqgrid_id").jqGrid({
...
   onSelectRow: function(rowId){ 
      $("#jqgrid_id").expandSubGridRow(rowId); 
   },
...
});

EDITED: on GridComplete event

jQuery("#jqgrid_id").jqGrid({
...
   gridComplete: function(){ 
      var rowIds = $("#jqgrid_id").getDataIds();
      $.each(rowIds, function (index, rowId) {
        $("#jqgrid_id").expandSubGridRow(rowId); 
      });
   },
...
});
John Hartsock
Can I expand the subgrid without the user having to click on anything? For example, after the jqgrid and subgrid have finished loading, the subgrid is automatically expanded.
Trevor
sure in that case use the onGridComplete Event.
John Hartsock
What would I use for the rowID?
Trevor
Sorry trevor. Probably should have been more specific. Check out my edited answer
John Hartsock
Thanks, exactly what I need. :)
Trevor
A: 

Change getDataIds() to getDataIDs()!

Stefan