Reputation: 22054
I have the main grid set to autowidth: true
, but how do I do the same with the subgrid so that it is the same width as the parent, and the columns are all relative/variable/percentage widths?
Upvotes: 1
Views: 3507
Reputation: 221997
You wrote in the comment to other answer the question
Why are the colModel, and subGridModel two completely different data structures?
Indirectly you answered yourself on your main question. The usage of old style subgrids (see "Advanced" / "Subgrid" on the official jqGrid demo) have too many restrictions. If you would use subgrid as grid (see "Advanced" / "Grid as Subgrid" on the the same jqGrid demo) you can create the same results, but you have much more flexibility. You can use for example formatters (inclusive custom formatters) use cellattr
and rowattr
callbacks, use autowidth: true
option in the subgrid and so on. You have exactly the same set of possibilities as in the main grid. If you define some common callbacks in $.jgrid.defaults
you can share the code of callbacks of subgrid and the main grid...
I can continue with the list of advantages of the usage of Grid as Subgrid. My short advise: use always only the feature.
Upvotes: 1
Reputation: 3123
The width of the subGrid will be set when it is initalized, and as it doesn't contain any data when it is built it will be the size of the total column widths. You can get around this by setting the width of the grid each time you load the subgrid
$('#ParentGridName, #SubGridName').jqGrid('setGridWidth', $('#IdOfHTMLElementHoldingGrids').width(), true);
This will synch up both the parent and child grid sizes. If you are worried about the window being re-sized as well you can call this as part of an event handler.
Ex.
window.onresize = function () { resizePageGrids() }
Upvotes: 1