Search code examples
jqueryjqgrid

jqGrid: How can I change the width of the jqGrid?


I would like to change the width of a jqGrid. I tried to set the width in my griddefinition:

   width: '800px'

Is there another way?


Solution

  • You could use the setGridWidth property

     $('#gridId').jqGrid('setGridWidth', '800');
    

    If you want the grid to re-size dynamically, hook into the window re-size function, but remember to set the initial width

     var DataGrid = $('#gridId');
    
     //sets the grid size initially
     DataGrid.jqGrid('setGridWidth', parseInt($(window).width()) - 20);    
    
     //handles the grid resize on window resize
     $(window).resize(function () { 
           DataGrid.jqGrid('setGridWidth', parseInt($(window).width()) - 20); 
     });