In jqGrid, is it possible to resize columns to fit the table width (original width) after hide a column?
Asked Answered
W

1

4

I am using shrinkToFit = true property to fit the table with columns width(proportional sizing), in the mean time I also want to hide a column but does not want to change the width of the table. If shrinkTofit is set true, the table width also shrinks with the amount of the width of the hidden column. Let me give an example,

Configuration:

ShrinkToFit = true
Table width = 800,
Two columns exist: 
ColumnA width=200,
ColumnB width=200

when jqgrid is constructed the widths will be calculated like that:

TableWidth = 800,
Width of ColumnA = 400, 
Width of ColumnB = 400

When ColumnB is set to hidden,widths will be (normal behaviour):

table width=400
ColumnA width =400

My Desired Behaviour:

table width = 800
ColumnA width = 800

Is is possible to achieve this behaviour?

thanks in advance, Alper.

Whitmer answered 12/10, 2011 at 18:51 Comment(0)
E
8

If I understand you correct you can just call setGridWidth method one more time with the current grid width and true as the next (shrink) parameter:

var myGrid = $("#list"),
    width = myGrid.jqGrid('getGridParam', 'width'); // get current width
myGrid.jqGrid('setGridWidth', width, true);

This will not change the width of the grid, but force the shrinking of the columns.

Evince answered 12/10, 2011 at 19:28 Comment(8)
It rocks.. Thank you. what I did was,at the begining set shrinkToFit= false, and than call setGridWidth one more time as you suggested.Whitmer
Thanks for your answer @Evince definitely you are one of the masters of JQGrid!!! :DGreff
Hello Oleg, Is there a way to remove the style width from the column header and use the custom css class? We are moving our application with twitter bootstrap responsive design and we need to use hidden-xs to hide some columns for mobile devices. However with current jQgrid design we are unable to make it. I have seen this SO answer to add my custom css class to the table header, but the width is calculated and unable to change. Is there a way to solve our problem or we need to use other plugins like data table?Bolick
@MuraliMurugesan: There are some possibilities, but I'm not sure that I correctly understand your problem. It would be better if you post separate question with the demo (jsfiddle demo for example) which shows your original jqGrid and the description what you what to make. I will try help you.Evince
Oleg, Just posted #30820119Bolick
@Milan: You are welcome! If you use Bootstrap then jsfiddle.net/OlegKi/andm1299/8 could be interesting for you too. It shows how to use Bootstrap classes like "hidden-xs" to automatically hide/show some columns on resizing the grid.Evince
@Evince i am already using bootstrap but now i have to use jqgrid like this , the issue for width got resolved , thanks to you but one issue is whenever i click on comment icon in jqgrid header , the scroll-bar goes back to the top of the current window. it does not preserves its own position. so, if you can help me in that.Scherle
@Milan: I develop alternative fork free jqGrid after changing license agreement by the main fork of jqGrid, making it commercial (see the prices) and renaming to Guriddo jqGrid JS. Sorry, but I can't help with with any problems with Guriddo. If you pay for the product you can expect the corresponding support at the Guriddo forum.Evince

© 2022 - 2024 — McMap. All rights reserved.