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.

@Amjad_Sahi Do we have any solution for this kind of problem? Is the aspose cells upgraded to perform this?

@abhinav4593,
Aspose.Cells has improved a lot in terms of features and performance. We have tried to assist user as much as possible. Currently we provide inserting column at a specific index and deleting columns from a specific index. I am afraid that MoveColumn() feature is not available yet. I have logged an investigation ticket to provide this feature and you will be notified here once any update is ready for sharing.

This requirement is logged as:
CELLSNET-47996-Option to move existing column in GridWeb

@abhinav4593,

Please ignore previous reply as I think you are using Aspose.Cells for Java and not Aspose.Cells.GridWeb. The feature of moving range(s) is already supported. See the sample code for your reference:
e.g.
Sample code:

 Workbook workbook = new Workbook("f:\\files\\Book1.xlsx");
        Worksheet worksheet = workbook.getWorksheets().get(0);
        Cells cells = worksheet.getCells();

        //Create a cell area: A1:A3
        CellArea ca = CellArea.createCellArea(0,0,2,0);
        //move the range/area to (starting from) F10 cell.
        cells.moveRange(ca, 9, 5);

        //Create a range
        Range myRange = cells.createRange("D1:D10");
        //Move the range to E1:E10
        myRange.moveTo(0, 4);
........... 

Let us know if you still want something else.

The issues you have found earlier (filed as CELLSNET-47996) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao

@abhinav4593,

In the newer version for GridWeb (Aspose.Cells for GridWeb v21.5) release, we have added the following APIs:

GridCells.MoveRange() method.

Moves the range.

GridCells.InsertRange() method.

Inserts a range with shift option.

GridCells.DeleteRange() method.

Deletes a range with shift option.