Hi,
I have a RadGridView with data driven from a RadDataPager and am working on having the data exported to Excel. Using MVVM I have a button that fires a command in the UserControls View Model with the command parameter set as the RadDataGrid, this performs the export (below). This is fine and exporting the current page of data works well, however issues occur when trying to export the whole dataset.
Looking around I have seen normally the solution to this is to change the DataPager PageSize to 0 before export, however this is an approach that hasn't worked for me with MVVM. I set the pageSize using a binding to the viewmodel, and was hoping changing the value would be as simple as follows;
However this doesn't change the value of Object o (i guess maybe a copy is made instead of passing the object reference?), I also tried directly setting the grids ItemsSource to my full datasource, but this doesn't seem to work either - On debugging the grid correctly has an ItemsSource with the right number of elements, this just doesn't seem to translate into being exported to Excel (do I need to do some kind of refresh on the data?)
I also tried using RowVirtualization to avoid using the DataPager completely, but this was incredibly slow (the window hung for about a minute then when rows were loaded scrolling was very choppy - suggesting it wasn't working correctly.)
I'm wondering if you could provide a best practice solution to this problem :)
Other info;
* Data passed in by binding (ObservableCollection)
* MVVM
Thanks
I have a RadGridView with data driven from a RadDataPager and am working on having the data exported to Excel. Using MVVM I have a button that fires a command in the UserControls View Model with the command parameter set as the RadDataGrid, this performs the export (below). This is fine and exporting the current page of data works well, however issues occur when trying to export the whole dataset.
Looking around I have seen normally the solution to this is to change the DataPager PageSize to 0 before export, however this is an approach that hasn't worked for me with MVVM. I set the pageSize using a binding to the viewmodel, and was hoping changing the value would be as simple as follows;
protected void ExportExcelClicked(object o)
{
PageSize = 0;
RadGridView grid = o as RadGridView;
string extension = "csv";
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{
using (Stream stream = dialog.OpenFile())
{
grid.Export(stream,
new GridViewExportOptions()
{
Format = ExportFormat.Csv,
ShowColumnHeaders = true,
ShowColumnFooters = true,
ShowGroupFooters = false,
});
}
}
//reset page size
PageSize = PAGESIZE;
}
However this doesn't change the value of Object o (i guess maybe a copy is made instead of passing the object reference?), I also tried directly setting the grids ItemsSource to my full datasource, but this doesn't seem to work either - On debugging the grid correctly has an ItemsSource with the right number of elements, this just doesn't seem to translate into being exported to Excel (do I need to do some kind of refresh on the data?)
I also tried using RowVirtualization to avoid using the DataPager completely, but this was incredibly slow (the window hung for about a minute then when rows were loaded scrolling was very choppy - suggesting it wasn't working correctly.)
I'm wondering if you could provide a best practice solution to this problem :)
Other info;
* Data passed in by binding (ObservableCollection)
* MVVM
Thanks