Can't find what you're looking for?

Contact us or post in our forums and we'll help you find an answer.

Re-Order C1OlapPanel Fields

Background:

By default, the fields in the C1OlapPanel control are sorted alphabetically in ascending order. However, in some scenarios, you may need to arrange these fields in a different order. For example, you may require that the fields follow the same order as the one followed by the columns in the Olap’s DataSource, which is also the order followed by columns in the raw grid.

This article shows you how to change the sorted order of fields in the C1OlapPanel control by arranging them in the same order as the columns in the DataSource of the Olap control.

Steps to Complete:

  1. Access the ListBox control that contains the fields ‘C1OlapFieldList’ using VisualTreeHelper. The function used in this article is available publicly at stack overflow: https://stackoverflow.com/a/1759923/9591476

  2. Once the element is accessed, get the data source of the OlapPage and store the name of the columns in their original order, using LINQ.

  3. Finally, arrange the fields by ordering the ItemsSource of the listbox accessed in step 1, by the column names stored in step 2.

Please see the full code below:

var list = FindChild(olapPage, "Fields");
if ((olapPage.DataSource as DataView).Table!= null)
{
       List columnNames = ((olapPage.DataSource as DataView).Table.Columns.Cast().Select(c => c.ColumnName).ToList();
       list.ItemsSource = (list.ItemsSource as C1.Olap.C1OlapFieldList).OrderBy(f => columnNames.IndexOf(f.Name));
}

Get the Latest Version of C1
Download the Free Trial Now