In the RadDataGrid, if the column order is rearranged, how can I get to that ordering?

1 Answer 78 Views
DataGrid
Christopher
Top achievements
Rank 2
Iron
Iron
Christopher asked on 06 Jul 2023, 09:05 PM | edited on 07 Jul 2023, 10:32 PM

Say I have a table with columns AA, BB, CC, DD and, via the More menu under the filtering and grouping options, I turn off the AA column and rearrange the others so that it is displayed as CC, BB, DD.

I then do:

var dataView = dataGrid.GetDataView();

var rows = dataView.Cast<DataRowView>().Select(x => x.Row).ToList();

Then if I iterate through the rows[index].ItemArray, the fields are in the original order (AA, BB, CC, DD). I can look at the RadDataGrid.Columns and see if the column IsVisible, but if I use the index in the ItemArray on the Columns, I won't get the right column.

What am I missing? It seems like the DataView should have the data in the order presented or that the Columns collection should have a way to map the ordering. After all, the DataView does present the filtering, grouping, and sorting correctly.

I wrote code to do my own mappings, but it's kind of ugly and seems unnecessary - there should be a way to either get the data in the order presented or get the columns in the order presented.

As for why I'm doing this - I'm using the DataGrid in a UWP and iPad Xamarin.Forms app to take report output and let the user's rearrange columns, filter, sort, turn off unwanted columns, etc. then export to Excel in a WYSIWYG fashion - the export should look like the current state of the DataGrid.

1 Answer, 1 is accepted

Sort by
1
Accepted
Ves
Telerik team
answered on 11 Jul 2023, 01:20 PM

Hi Christopher,

You are right, currently, there is no sync between the RadDataGrid Columns collection and the dataview items' array order. So please, keep the code you mentioned in place. I have logged a bug on your behalf and I have updated your Telerik points for bringing this to our attention.

Best regards,
Ves
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DataGrid
Asked by
Christopher
Top achievements
Rank 2
Iron
Iron
Answers by
Ves
Telerik team
Share this question
or