WebGrid 6.0 - SaveTablesStructureToXml Does NOT Save Moved Columns

3 replies. Last post: September 4, 2012 5:52 AM by Hans Kristian
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
A YousifMember

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.

 

All times are GMT -5. The time now is 3:19 AM.
Previous Next