Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2320
Fixed Header problem
posted

I want all columns to autofit the grid.  With the UltraWinGrid, there was a property called AutoFitStyle.  I'd set it to Resize all Columns.

In UltraWebGrid, is there any equivalent?

I found that by setting ColWidthDefault="" in the html source, it seems to have similar functionality.  However, I have grid where the first column in the grid is Fixed.  As soon as I set the column to fixed, all column headers except the fixed column collapse like an accordian (even thought the rows look normal).  As soon as you try to resize on of them, the column headers redraw and correct all columns(?????).  To fix that I manually set all Column widths but this causes the Column Header and the Rows to get out of alignment somehow.  Is there anything else I need to set or can do to fix this?

Here is how I set the fixed header in code.  

I have an UltraWebGrid that I am binding to a strongly typed dataset in code like this...

grid.DataSource = _ds;
grid.DataMember = "TableName";
grid.DataBind();

In code we setup the grid's layout like so

grid.DisplayLayout.UseFixedHeaders = true;

 UltraGridColumn col = gridTransaction.Columns.FromKey("ColumnName");
 col.Header.Caption = "Transaction Type";
 col.AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.No;           
 col.Header.Fixed = true;
 col.Header.Style.HorizontalAlign = HorizontalAlign.Center;
 col.Width = Unit.Pixel(260);
 col.Move(0);

// Initialize TestMode column

col = grid.Columns.FromKey("ColumnName");
col.Header.Caption = "Test/Production";
col.Header.Style.HorizontalAlign = HorizontalAlign.Center;
col.Width = Unit.Pixel(100);
col.Move(1);

... all other columns created the same 

If I comment out the 2 fixed header lines, then the grid columns will autofit correctly. 

Parents
No Data
Reply
  • 45049
    posted

    The following forum thread addresses information on how to "auto-fit" columns in WebGrid:
    http://forums.infragistics.com/forums/t/12670.aspx

    As noted in this thread, you need to have the grid's DisplayLayout.TableLayout set to Auto in order to have your columns automatically-sized.  This uses the functionaliity of an HTML table to automatically size columns, which is done by the browser.

    Whenever you set UseFixedHeaders to true, or StationaryMargins to any value other than None, your grid must have its DisplayLayout.TableLayout property set to Fixed.  This means that your grid columns can no longer auto-size, similar to an HTML table whose table-layout attribute is set to fixed.

    In this scenario, you can likely use some JavaScript to automatically size columns for you.  The following article from our online Knowledge Base shows how to do this when double-clicking between columns; it should be relatively straightforward to call similar logic from the grid's client-side InitializeLayout event instead:
    HOWTO: Auto size column in WebGrid when double clicking column divider

    As a note, I don't recommend using this approach if you're loading a lot of data in the grid.  This is because the logic requires looping through all of the rows in the grid via JavaScript, which can become very time-consuming.  The logic can't be done server-side, since the server has no concept of how an individual browser instance might actually render.

Children