I wish to extend this sample so that all rows are initially selected and the checkbox is in the header is also selected after the sfdatagrid is loaded with data.
I've been able to set all the checkboxes on from the viewmodel, however I haven't had any luck getting the sfdatagrid.selectall() to work so that the rows are selected and highlighted after the data is loaded. I've tried adding code to the sfdatagrid loaded event without success.
DYDeivaselvan Y Syncfusion Team December 3, 2018 04:45 AM
Thank you for contacting Syncfusion support.
You can achieve your requirement by invoking the SelectAll method in Loaded event of SfDataGrid and override the SelectAll method of GridSelectionController to set value to the Checkbox. Please refer the below sample to meet your requirement to set Checked state to the Checkbox and select all the rows in the DataGrid during initial loading. Try running this sample and let us know if this helps you. http://www.syncfusion.com/downloads/support/forum/141254/ze/SFDATA~156213210.zip
ALAllanDecember 3, 2018 12:15 PM
Thanks for your reply. I downloaded and ran your sample and then implemented similar logic in my code.
My situation is complicated by an asynchronous data load in the view model. This is being trigger by a window interaction trigger
which fires an asynchronous data load of the sfdatagrid. When it hits the await statement, the control is released to the datagrid code behind event which initiaties the SelectAll(). Unfortunately the viewmodel hasn't finished loading the data at this point so the RowSelectionDocsController does not have a complete data set. I can get past this problem by forcing the data load to be synchronous however I was hoping to keep the data access asynchronous.
Is it possible to prevent the event in your example from firing until the data load in the view model has completed?
DYDeivaselvan Y Syncfusion Team December 7, 2018 12:34 AM
Thanks for the update.
Kindly share your code implementation on how you are populating the data in ViewModel asynchronously and this may help us to mimic the same at our end to investigate further on this and provide you the appropriate solution at the earliest.
DYDeivaselvan Y Syncfusion Team December 7, 2018 05:47 AM
We have also suspect you may set ItemsSource of the DataGrid asynchronously after loaded the DataGrid control. If this is your case, then you may invoke SelectAll method within the ItemsSourceChanged event of DataGrid as like below code example.
If still your requirement is not meet with any of our proposed solution, then kindly provide the details as we requested earlier such as asynchronous code implementation of Data population in ViewModel and how it was bind with the DataGrid. Thereby we could analyze further and update you with the appropriate solution at the earliest.
ALAllanDecember 7, 2018 12:23 PM
Your last suggestion to use the itemssourcechanged event has fixed my problem.
I have the itemssource attached to an observable collection that is being loaded asynchronously via the interaction trigger.
Thank you for your help.
DYDeivaselvan Y Syncfusion Team December 9, 2018 11:52 PM
Thanks for the update.
We are glad to know that your issue has been fixed by handling ItemsSourceChanged event. Please let us know if you need any further assistance.