How to set jqGrid default to collapse
Asked Answered
E

3

5

i have a working jqgrid table and I wanted the default table to collapse on load. I have checked the site's documentation but I couldn't find the option for this. The button is has a class ui-icon-circle-triangle-n.

many thanks.

Epicontinental answered 13/12, 2011 at 9:42 Comment(1)
Do you speak about treegrid collapsing or about the grouping collapsing?Caesium
P
3

I once did this by calling .click() on the collapse button after loading the table. Maybe not the most robust solution, but it worked for me.

Politburo answered 13/12, 2011 at 9:49 Comment(1)
You should probably try to find a more specific selector than just ui-.icon-circle-triangle-n though, as that class is used for setting the background of the element. Using only that selector would fire the click event on all such elements in the document.Politburo
T
9

hiddengrid is a property of the grid that will accomplish what you want. See the last property set in the below example.

<script type="text/javascript">
     jQuery(document).ready(function () {
         var grid1 = jQuery("#list1").jqGrid({
             url: '/controller/action/',
             datatype: 'json',
             mtype: 'POST',
             colNames: ['Col1', 'Col2'],
             colModel: [
      { name: 'Col1', index: 'Col1', width: 22, align: 'left'},
      { name: 'Col2', index: 'Col2', width: 22, align: 'left'}
      ],
             sortname: 'Col1',
             sortorder: "asc",
             caption: 'Sample Grid',
             rowNum: 10,
             pager: '#,
             hiddengrid: true

     });
</script> 
Tredecillion answered 2/5, 2012 at 3:59 Comment(1)
That worked perfectly for me! Other than the accepted answer, this answer will wait to trigger loading the data until you expand the grid. So I prefer this option, thank you for this hint!Scull
P
3

I once did this by calling .click() on the collapse button after loading the table. Maybe not the most robust solution, but it worked for me.

Politburo answered 13/12, 2011 at 9:49 Comment(1)
You should probably try to find a more specific selector than just ui-.icon-circle-triangle-n though, as that class is used for setting the background of the element. Using only that selector would fire the click event on all such elements in the document.Politburo
B
1

Recently I found a better solution and more efficient than trigger the click.

Just add the groupingView element with the groupCollapse option in the gridOptions element.

Some like that:

// grid options
{
   groupingView: {
       //Collapse all
       groupCollapse: true
   }
}
Boney answered 6/10, 2017 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.