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

sfDataGrid event on column order

Hi,
I am controlling the column ordering, visibility, filtering etc everything from the view model by writing an adapter to separate view from view model. Things are working nice so far.
However, I need to preserve the order of the column that the user sets in once session so that I may represent him the same order when he launches the application again.
For this to happen, I need a event that will help me intimate the ViewModel that column reordering has happened. I saw this thread:
https://www.syncfusion.com/kb/2437/how-to-set-back-the-initial-columns-order-after-reordering-the-columns
And also read the documentation here:
https://help.syncfusion.com/xamarin/sfdatagrid/columndraganddrop
From the documentation, I see we can track the dragging of a column but can't find anything that can help us hook to the drop. Am I missing something.
All I need is a place to hook to when the user has reordered a column.

regards,
Sid

3 Replies

DY Deivaselvan Y Syncfusion Team November 30, 2018 10:19 AM UTC

Hi Vasudeva,

Thank you for contacting Syncfusion support.

We have analyzed your query and we suspect that you have required to Serialization and Deserialization the order of the columns in SfDataGrid. DataGrid does not support to maintain to order of the columns during Serialization and Deserialization and it will maintain only data operation settings. However, we have prepared the simple sample by maintaining the order of the columns during DataGrid reloading by storing the columns order in xml file when it was unloaded. Please find the sample to illustrate this from the below link and let us know if this helps you.

http://www.syncfusion.com/downloads/support/forum/141114/ze/EditingDemo-2088218050.zip

Regards,
Deivaselvan 



VN Vasudeva Naik November 30, 2018 11:02 AM UTC

Hi,
I understand that we can save and restore the column order while loading and unloading. But in real life applications, flows arent that easy and we have to go by the user requirements rather than the functionalities offered by third party we use. Of course there are workarounds (seems we have to take one), but that needs lot of wrapper code which we want to avoid due to time constraint. 
Having said that, an event once a column is dragged and dropped (giving info about the colum and old/ new index) is a very logical thing to have. I see you have event to track the drag event of columns (cant see why we should not have drop event). 
From your reply, I assume there is no event to mark drop of a column. Can you please bring this to the notice of your dev? 
Thanks,



DY Deivaselvan Y Syncfusion Team December 3, 2018 03:46 PM UTC

Hi Vasudeva,

You can use the QueryColumnDragging event to get the old and new column index when column dropped. Please refer the below code example which illustrate the same.

 
this.dataGrid.QueryColumnDragging += DataGrid_QueryColumnDragging; 
 
private void DataGrid_QueryColumnDragging(object sender, QueryColumnDraggingEventArgs e) 
{ 
    if(e.Reason == QueryColumnDraggingReason.Dropped) 
    { 
        int oldColumnIndex = e.From; 
        int newColumnIndex = e.To; 
    } 
} 

Please let us know if you have any other questions.

Regards,
Deivaselvan 


Loader.
Live Chat Icon For mobile
Up arrow icon