iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
One of the features we offer on our custom grids is to transparently save the user's changes to our database when they do things like group, sort, resize, move columns and so on. However, the problem we've run into is that the moving of columns is not saved by SaveTablesStructureToXml.
First, neither OnColumnResize or OnColumnMove post back, even when the return is true. So we have to force the post back by gathering the info we need and then using the grid.SendCustomRequest per the example below.
function OnColumnMove(controlId, tblName, sourceIndex, targetIndex, sourceColumn, targetColumn) { oGrid = HaveGrid(controlId); if (oGrid == null) { return true; } // note that the InterSoft internal javascript does NOT // check for the variable type and assumes it a string. // So any variable that's not a string, needs to be // cast as so prior to passing it. oGrid.AddInput(ActionCustom, ActionColumnMove); oGrid.AddInput("UserColumnSourceName", sourceColumn.Name); oGrid.AddInput("UserColumnSourceIndex", sourceIndex.toString()); oGrid.AddInput("UserColumnTargetName", targetColumn.Name); oGrid.AddInput("UserColumnTargetIndex", targetIndex.toString()); oGrid.SendCustomRequest(); return true; }
Once it posts back, the call to SaveTableStructureToXml does not show the changed column position. I tried to assign the Position property on the server-side in OnInitializePostBack but that has no impact as seen here:
string strSourceColName = CPRISMStrLib.GetStr(Page.Request["UserColumnSourceName"]); string strTargetColName = CPRISMStrLib.GetStr(Page.Request["UserColumnTargetName"]); int iOldPosition = Int32.Parse(CPRISMStrLib.GetStr(Page.Request["UserColumnSourceIndex"])); int iNewPosition = Int32.Parse(CPRISMStrLib.GetStr(Page.Request["UserColumnTargetIndex"])); ISNet.WebUI.WebGrid.WebGridColumn colSource = null; ISNet.WebUI.WebGrid.WebGridColumn colTarget = null; // if we have a valid source column, then set its position // to the target the user has selected if (CPRISMStrLib.IsVs(strSourceColName)) { int iColIdx = grid.RootTable.Columns.IndexOf(strSourceColName); if (iColIdx >= 0) { grid.RootTable.Columns[iColIdx].Position = iNewPosition; colSource = grid.RootTable.Columns[iColIdx]; } }
Since the above didn't work, I even added code to remove the column object and insert it at the new position and that didn't work either:
// since reassigning the Position property is not "remembering" or "applying" // the position when SaveTablesStructureToXml() is called, it looks like // I'll have to remove and reinsert the column at the desired position // in the Columns collection manually if (colSource != null) { grid.RootTable.Columns.Remove(colSource); grid.RootTable.Columns.Insert(iNewPosition,colSource); }
I'm not sure what to do at this point as this seems like a bug unless I'm missing something? Note that if after a process that does post back on its own like sorting a column is done, then the columns moved prior to, sorting for example, are remembered and saved.
This is consistent behavior so you should be able to duplicate. Let me know if you need any other information. Thank you.
I found a solution to this. It looks like making the changes on the grid object passed to OnInitializePostBack doesn't trickle down to the base class call, i.e., base.OnInitializePostBack.
I changed the grid. calls to this., e.g., this.RootTable. and so on and that seems to work fine. It would be nice if the grid object handled these the way it handles the sort, groupings and so on, rather than me having to put "workaround" code in. I like the flexibility, but am not sure why you wouldn't include this as part of the table structure save/restore settings. Thanks.
Hi Yousif,
Is it possible for you to send the code to how you achieved saving and loading the webgrid structure? I have a similar requirement and what to get some help.
Thanks!
I’m sorry for the late response.You could save the WebGrid’s structure to XML file, use this snippet code:
WebGrid1.SaveTablesStructureToXml(Server.MapPath("WebGridTableStructure.xml"));
Then you could load the structure from XML file, use this snippet code:
WebGrid1.LoadTablesStructureFromXml(Server.MapPath("WebGridTableStructure.xml")); WebGrid1.RebindDataSource();
Please have review on my sample as well and let me know your response.Hope this helps. Thank you.Regards,Hans.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname