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
405
Groupby and sort multiple columns
posted

Hi,

I have 3 columns by the name of level1name,  level3name, level3name to groupby. But I want to sort these columns by level1position,level2position,level3position.

I am creating one class GroupByComparer : IComparer which implements Icompare interface.

 I am calling this class in for loop for each columns. But this gets execute only for last column, not for all the column. This is sorting level3position for sorting not for all. please tell me whats the issue. I want to sort all the columns.

for (int i = 1; i <= minLevel; i++)

{

string groupColName = "level" + i + "Name";

string groupPos = "level" + i + "Position";

DataProvider.DataProvider.Instance.OverviewGridColumnName = groupPos;

gdOverView.DisplayLayout.Bands[0].Columns[groupColName].GroupByComparer = new GroupByComparer();

band.SortedColumns.RefreshSort(true);

}

 

 

internal class GroupByComparer : IComparer
{

public int Compare(object x, object y)

{

try

{

UltraGridGroupByRow rowX = (UltraGridGroupByRow)x;

UltraGridGroupByRow rowY = (UltraGridGroupByRow)y;

if (rowX.Rows.Count == 0 && rowY.Rows.Count == 0)

return 0;

if (rowX.Rows.Count == 0)

return -1;

if (rowY.Rows.Count == 0)return 1;

 

object xValue = GetSortByValue(rowX);

object yValue = GetSortByValue(rowY);

// return ((IComparable)((UltraGridGroupByRow)rowX).Value).CompareTo(((UltraGridGroupByRow)rowY).Value);

return Convert.ToInt32(xValue).CompareTo(Convert.ToInt32(yValue));

}

catch (Exception ex)

{

// Logger.Write(ex);

return -1;

}

}

 

private object GetSortByValue(UltraGridGroupByRow groupByRow)

{

string columName = DataProvider.DataProvider.Instance.OverviewGridColumnName;if (!(groupByRow.Rows[0] is UltraGridGroupByRow))

{

return groupByRow.Rows[0].Cells[columName].Value;

}

return GetSortByValue((UltraGridGroupByRow)groupByRow.Rows[0]);

}

}

}

  • 53790
    posted

    Hello Rosymalhotra,

    I`m not familiar with your scenario, but maybe will be better to call 
    ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Add("Column Key",true,false) for your columns. Also when you have "Multi sort" the order of sorted columns is important.
    0ne possible reason to have such kind behavior, could be if you didn`t set the property
    For example:
    -    ultraGrid1.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.ExternalSortMulti;
    Please let me know if you have any further questions.
    Regards