This is a migrated thread and some comments may be shown as answers.

Radgrid persistence wrong column width

6 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mircea
Top achievements
Rank 1
Mircea asked on 09 May 2012, 10:21 AM
Hej, im using ur example :
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx

 

 

My problem is that when I'm getting the column.headerStyle.width is not the right ones. What i mean by that is that only the resized column acctualy changes width value where the others just keep having the same as before resizing┬┤, even if they do acctually change like f.eks in the example, but its probally just visual in my case.

what do I do wrong?

Here is my savesettings string:



private
string SaveSettings()  

object[] gridSettings = new object[3];  

//Save groupBy 

 

GridGroupByExpressionCollection groupByExpressions = gridInstance.MasterTableView.GroupByExpressions; 

object[] groupExpressions = new object[groupByExpressions.Count];  


int
count = 0; 

 

foreach(GridGroupByExpression expression in groupByExpressions)  

{

groupExpressions[count] = ((IStateManager)expression).SaveViewState();

count++;

}

gridSettings[0] = groupExpressions;

 

//Save sort expressions

 

gridSettings[1] = ((

IStateManager)gridInstance.MasterTableView.SortExpressions).SaveViewState();  

 

//Save columns order 

 

 

int columnsLength = gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length;

 

Pair [] columnOrder = new Pair[ columnsLength ];  

ArrayList allColumns = new ArrayList( columnsLength );

 

allColumns.AddRange(gridInstance.MasterTableView.Columns );

allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns);

 
int i = 0;  

foreach( GridColumn column in allColumns ) 

{
Pair p = new Pair(); 

p.First = column.OrderIndex;

p.Second = column.HeaderStyle.Width;

columnOrder[i] = p; 

i++;

}

gridSettings[2] = columnOrder;
 

// Serialize and return  

 

LosFormatter formatter = new LosFormatter();  

StringWriter writer = new StringWriter();

formatter.Serialize( writer, gridSettings ); 

return writer.ToString(); 

}

Regards,
Mircea

6 Answers, 1 is accepted

Sort by
0
Mircea
Top achievements
Rank 1
answered on 09 May 2012, 12:00 PM
Hej, no one else have the same issue? or?

Greetings,
Mircea
0
Joshua
Top achievements
Rank 1
answered on 09 May 2012, 07:47 PM
I have the same issue but haven't found a solution.  

I even tried setting the columns as percentage widths but in that case it won't recognize any user resize of the columns.  

0
Pavlina
Telerik team
answered on 14 May 2012, 03:02 PM
Hi,

The columns width should be saved and retrieved with the GridSettingsPersister class. Can you confirm that you have set grid columns width initially? Any additional information on your scenario and grid setup might help in finding a resolution for you.

However, I tested the described behavior in our online example. The grid columns do not have their width set and after resizing, the new width is persisted as expected. Can you specify what differs in your scenario?


Kind regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Joshua
Top achievements
Rank 1
answered on 16 May 2012, 04:51 PM
Pavlina,

Thank you for your response. 

I've continued working on my implementation and am able to persist the column width settings and have them replicated exactly.   But only if the ClientSettings.Resizing.AllowColumnResize property is set to true.   I'm using autogenerated columns as well.  As the columns are generated each one is assigned a width so a width is explicitly set for every column.  

What I'm trying to implement is a grid where an admin can set the column widths, save them to the database, and then present that grid to a user with the exact grid widths that the admin set.  The user will not be permitted to modify the grid in any way.  So when the admin views the grid, the ClientSettings.Resizing.AllowColumnResize  property is set to true, but if a user is viewing it, the property is false. 

If I set the property to false the column widths are taken as suggestions and the column's widths are determined by the content.   I've attached two images, Capture1 and Capture2.    Capture1 shows the grid with the AllowColumnResize = true and I've set the column widths manually.  These settings are persisted.  Capture2 shows the grid when the AllowColumnResize = false.  The first column has rather lengthy strings and it pushes the width open.   I expect it to look like Capture1.

I've tried setting the width of the grid and the MasterTableView to a specific pixel width as well to no avail.  

Is there a property I'm missing that would allow me to set column widths even when AllowColumnResize is false.  I hope its something silly I missed in the documentation.

Thank you,
Joshua
josh.weiner@vivaki.com
0
Joshua
Top achievements
Rank 1
answered on 16 May 2012, 05:10 PM
Forgot to mention that I also have the TableLayout property set to Fixed, not Auto.
0
Joshua
Top achievements
Rank 1
answered on 16 May 2012, 05:30 PM
I was able to resolve this myself so I'll post my solution for anyone searching for an answer.

The issue was that I was only setting the HeaderStyle.Width property in the ColumnCreated event handler.  I added the ItemStyle.Width property as well and that froze the columns into place.   

I found the solution here:
http://www.telerik.com/community/forums/aspnet-ajax/tooltip/fix-radgrid-column-width-is-the-tooltip.aspx 
Tags
Grid
Asked by
Mircea
Top achievements
Rank 1
Answers by
Mircea
Top achievements
Rank 1
Joshua
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or