We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

get GridDataControl sorted list

I have a GridDataControl with few columns. I would like to retrieve the sorted list after clicking on the header.

To do that, I suscribe to SortColumns.CollectionChanged event and retrieve data from Model.View.Records but at this time, the list seems not be sorted yet.

Is there a way to do that ?

Thank you,

3 Replies

GK Ganesan K Syncfusion Team December 14, 2009 04:31 PM UTC

Hi Thierry,

Thanks for using Syncfusion products.

You can achieve this by listen the MouseLeftButtonUp event like below.

[C#]

dataGrid.MouseLeftButtonUp += new MouseButtonEventHandler(dataGrid_MouseLeftButtonUp);

void dataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
GridDataControl dataControl = sender as GridDataControl;
var rowColIndex = dataControl.Model.Grid.PointToCellRowColumnIndex(e.GetPosition(dataControl.Model.Grid));
var style = dataControl.Model[rowColIndex.RowIndex, rowColIndex.ColumnIndex];

if (style.CellType == "HeaderCell")
{
// Your custom code comes here.
var record = dataControl.Model.View.Records.First();
Orders order = record.Data as Orders;

}
}

Please let us know if you need any more details.

Thanks
Ganesan


SH Shwe September 10, 2013 08:52 AM UTC

var record = this.grd_WatchList.Model.View.Records;

ObservableCollection <InstrumentEntry> sortedCollection = record as ObservableCollection<InstrumentEntry>;

Hi,

In this code, although record has sorted data value, sortedCollection becomes null.

how can i do to get data value at sortedCollection

 

Thanks and Best Regards

 

 

 

 



GA Gobinath A Syncfusion Team October 1, 2013 08:03 AM UTC

Hi Shwe,

Thanks for your update.

We have analyzed your query and you can get the sorted collection from the View by using the following code snippet

Code snippet[C#]:

this.syncgrid.Model.Table.SortColumnsChanged += new GridDataSortColumnsChangedEventHandler(Table_SortColumnsChanged);

void Table_SortColumnsChanged(object sender, GridDataSortColumnsChangedEventArgs args)

 {

   this.Dispatcher.BeginInvoke(new Action(() =>

     {

       var records = this.syncgrid.Model.View.Records;

       var SortedCollection = records as EnumerableRecordsWrapper;

       if (SortedCollection != null)

        {

         // we can access the sorted record here.

        }

      }), DispatcherPriority.ApplicationIdle);

 }

Please let us know if you have any queries.

Regards,

Gobinath A.

 


Loader.
Live Chat Icon For mobile
Up arrow icon