Free Support Forum - aspose.com

Custom ordering of columns

Hi

My grid will be showing data for a twelve month period. However, I need to be able to reorder the month columns based on a parameter. The user is able to select the starting month of a twelve month period, and I cannot sort this through SQL as sorting is already applied on other columns. The columns are always return in sequential order from the database i.e. Jan, Feb, Mar…

How do I reorder the columns in the grid?

Thanks.

Hi,

Do you mean you want to sort the data in column(s), well you may use Cells.Sort() method and sort the data in Asc or Descending order. Alternatively you may utilize order by clause in your SQL query to set the sort order or if you want to filter your desired data based on your starting month, you may also use your own query (Select statement) for it.

To sort data using the grid, please check the source code of Sort demo from Common category in our featured demos:

Grid Demos

Thank you.

No, I don’t need to sort the data in the columns. I need to be able to control the actual column order in the grid.

Data returned from the database is ALWAYS ordered by month order i.e. Jan, Feb, Mar, Apr…etc. However, although the months are always in the correct order, they may not always be from the same calendar year, i.e.

Jan (2007) – Feb (2007) – Mar (2007) – Apr (2006) – May (2006) – Jun (2006)… Dec (2006)

I need to be able to change the column order to the following:

Apr (2006) – May (2006) – Jun (2006)… Dec (2006) – Jan (2007) – Feb (2007) – Mar (2007)

The [Year] data is not returned in the dataset so I cannot sort the data by year and then month.
How do I move columns in the grid?

Hi,

If you are implementing databinding, you may try to utilize gridweb's Worksheet Designer editor and use its BindColumn collection editor to shift your desired columns at your specified location using up / down arrows.

Thank you.

Sorry, but this is no help. I need the reordering to be done at runtime since the column order needs to be done based on user parameters.

Is this possible?

I find it strange that your component doesn’t have a function like MoveColumn(int index) or perhaps something like MoveColumn(sourceColumn, index). It’s rather disappointing…

Anyone there…?
Any ideas…?

Hi,

Thanks for your suggestion, we may consider moving cols feature in our future versions soon.

Thank you.

Hi,

I think you may resort the BindColumn by calling the Remove and Insert method of the WebWorksheet.BindColumns collection. For an example:

BindColumn column = sheet.BindColumns["price"];

sheetBindColumns.Remove(column);

sheetBindColumns.Insert(4, column);

Wish this helps.