Saving ASPxGridView Column Width Data

978 views Asked by At

I'm maintaining a project that uses DevExpress ASP.NET v13.2 controls and within it I have an ASPxGridView that displays all sorts of information. Recently when doing some work on the layout of this grid, I noticed that the column widths are not being saved at all. It seems only column ordering and column visibility are being stored.

Here's what I've got client-side:

<dxwgv:ASPxGridView ID="ASPxGridView" runat="server"
                    AutoGenerateColumns="False"
                    ClientInstanceName="grid"
                    KeyFieldName="ClientId"
                    Width="100%"
                    OnHtmlRowPrepared="ASPxGridView_HtmlRowPrepared"
                    OnCustomCallback="ASPxGridView_CustomCallback"
                    OnClientLayout="gridView_ClientLayout">
  <SettingsBehavior ColumnResizeMode="NextColumn" AllowFocusedRow="True" />
  <SettingsCookies Enabled="True"></SettingsCookies>
  <SettingsText EmptyDataRow="No queries found for the current criteria." />
  <Settings ShowFilterRow="True" ShowGroupPanel="True" ShowFilterRowMenu="True" GridLines="None" />
  <ClientSideEvents BeginCallback="OnGridBeginCallback"
                    EndCallback="OnGridEndCallback"
                    ColumnResized="function(s, e) {
                                   e.processOnServer = true;}">
  </ClientSideEvents>
          <Columns>

So, according to the snippet above, whenever a column is resized, the event is processed server side and sent through to the girdView_ClientLayout method (this works).

Here's what girdView_ClientLayout looks like:

protected void gridView_ClientLayout(object sender, ASPxClientLayoutArgs e)
{
  //if in saving mode continue.
  //compare GridView's current layout (e.LayoutData) info to that stored on Db for this user.
  //if different, save new layout to Db.
  //refresh layout, i.e. read new user layout from Db.
  //otherwise ignore as to reduce unnecessary extra Db interaction.
}

So according to my understanding, e should contain a property called LayoutData which is a human unreadable logical string that should have layout information such as columns visible, column order, grouping, column widths, etc that only the gridview can understand. However, stepping through the flow, I notice the string passed to gridView_ClientLayout has no column width information. My above method ignores the new layout information as technically it sees no change to the layout data and therefore does not save the layout! It then refreshes the grid (reads the user's layout from the Db) which means column widths are reset to that of whatever is saved in the Db.

Here's an example of the LayoutData string before width is resized:

"page1|sort1|a20|conditions14|1|3|4|3|6|3|8|3|10|3|12|3|13|3|14|3|15|3|19|3|20|3|21|3|22|3|23|3|visible24|f0|f3|t0|f16|f2|f16|t1|f16|t6|f16|t7|f16|t4|t5|f10|f9|t11|t12|f14|f13|t8|f16|f13|f16|width24|e|e|60px|e|e|e|e|e|e|e|e|e|300px|e|e|e|e|e|e|e|e|e|e|e"

Here's what the LayoutData looks like being passed to girdView_ClientLayout when rezising occurs:

"page1|sort1|a20|conditions14|1|3|4|3|6|3|8|3|10|3|12|3|13|3|14|3|15|3|19|3|20|3|21|3|22|3|23|3|visible24|f0|f3|t0|f16|f2|f16|t1|f16|t6|f16|t7|f16|t4|t5|f10|f9|t11|t12|f14|f13|t8|f16|f13|f16|width24|e|e|60px|e|e|e|e|e|e|e|e|e|300px|e|e|e|e|e|e|e|e|e|e|e"

Exactly the same! I'm expecting something like the above string but with more sections ending in px. Sort of like:

'page1|visible23|f0|f-1|t0|f1|f-1|f2|t1|f3|f4|f4|t3|f5|t2|f6|f6|f6|t4|f7|f11|f7|t5|t6|f8|width23|e|200px|100px|e|e|e|56px|e|e|e|150px|e|200px|e|e|e|200px|e|e|e|120px|128px|e'

(Notice the various random sections ending in px) If I were to manually edit these px sections in the Db and run the app, the columns are sized accordingly so it's definitely a problem saving from the grid, not loading to it.

I'm planning on ditching save/load of this human unreadable gridview layout string soon as it has been giving me plenty of headaches whenever clients desire new columns. I'll be implementing an XML alternative soon but even then, it too requires column width information which is not stored in ASPxClientLayoutArgs.LayoutData meaning I'd have to implement a dirty hack to inject this column width information into the XML structure. But that's a problem for another day.

Anyone have any suggestions? This is not a huge problem, I mean it's just column widths, but my scrum master would really like it included in our next deploy (which is being delayed by this problem). He's a really cool guy and I'd really hate to disappoint him with something so small and insignificant.

Thanks guys, Jean-Pierre

1

There are 1 answers

0
Jean-Pierre Damstra On

I managed to find some deprecated code that was screwing with the layout functionality of the gridview.