The requested page is not available for the requested platform. You are viewing the content for Default platform.

Create Data Extract

  • 5 min to read

A data extract is a compressed snapshot of data obtained from the existing data source.

Note

Data Extract does not support the OLAP Data Source.

Create a Data Extract with the Data Source Wizard

To create a new data extract from the existing data source, perform the following steps.

  1. Click the New Data Source button in the Data Source ribbon tab.

    NewDataSourceButtonRibbon(Extract)

  2. On the first page of the invoked Data Source Wizard dialog, select Data extract and click Next.

    DataSourceWizard_Extract

  3. On the next page, select whether to create a new data extract or load data from the extract data file.

    DataSourceWizard_Extract_NewOrExisting

    • To create a new data extract, select Create a new data extract from the existing data source and specify the Data Source and Data Member. Click Next.
    • To establish a connection to an existing data extract, select Load an existing data extract from a file and select the .dat file. Click Finish.
  4. (Conditional) The next page appears if you create the data extract from the Entity Framework Data Source or Object Data Source. The page allows you to select the fields to store in the data file.

    DataSourceWizard_Extract_SelectFields

  5. On the next page, you can specify the filter applied to data. Review the Filter Data via the Filter Editor article for more information.

    DataSourceWizard_Extract_FilterData

    You can limit the amount of data to extract. Enable the Limit rows to extract option and specify the number of rows. Click Next.

    Note

    Use the Preview button to see the data that the resulting data extract contains.

  6. (Conditional) The next page appears if the original data source contains parameters ( the parameterized SQL filter query with dashboard parameters).

    DataSourceWizard_Extract_SpecifyParameterValues

  7. On the final page, specify a path to the file that contains the resulting data extract.

    DataSourceWizard_Extract_Finish

    Click Finish. This action creates the data extract and displays its fields in the Data Source Browser. You can use this data extract as a regular data source.

Create a Data Extract in Code

Create the DashboardExtractDataSource class instance and specify the following:

Finally, add the created DashboardExtractDataSource object to the Dashboard.DataSources collection.

Example

This example demonstrates how to create the Extract data source, replace existing dashboard data sources with Extract data sources and update the Extract data file.

The DashboardViewer loads a dashboard. The dashboard is initially bound to the Microsoft SQL Server database file (.mdf) with the DashboardSqlDataSource.

The CreateExtractAndSave method creates the DashboardExtractDataSource based on the original data source, adds the newly created data source to the dashboard, iterates over dashboard items to change the data source settings, and finally saves the modified dashboard and the Extract data file.

The UpdateExtract method calls the DashboardExtractDataSource.UpdateExtractFile() method for each Extract data source in the dashboard.

Note

The complete sample project WinForms - Dashboard with Extract Data Source is available in the DevExpress Examples repository.

using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using System.Linq;

namespace ExtractDataSourceExample
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
            dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;
            dashboardViewer1.LoadDashboard("DashboardTest.xml");
        }

        private void CreateExtractAndSave()
        {
            DataSourceCollection dsCollection = new DataSourceCollection();
            dsCollection.AddRange(dashboardViewer1.Dashboard.DataSources.Where(d => !(d is DashboardExtractDataSource)));
            foreach (var ds in dsCollection)
            {
                    DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource();
                    extractDataSource.ExtractSourceOptions.DataSource = ds;

                    if (ds is DashboardSqlDataSource)
                        extractDataSource.ExtractSourceOptions.DataMember = ((DashboardSqlDataSource)(ds)).Queries[0].Name;

                extractDataSource.FileName = "Extract_" + ds.Name + ".dat";
                    extractDataSource.UpdateExtractFile();
                    foreach (DataDashboardItem item in dashboardViewer1.Dashboard.Items)
                        if (item.DataSource == ds)
                            item.DataSource = extractDataSource;
            }
            dashboardViewer1.Dashboard.DataSources.RemoveRange(dsCollection);
            dashboardViewer1.Dashboard.SaveToXml("Dashboard_Extract.xml");
        }

        private void UpdateExtract()
        {
            dashboardViewer1.ReloadData();
            foreach (var ds in dashboardViewer1.Dashboard.DataSources.Where(d => d is DashboardExtractDataSource))
            {
                ((DashboardExtractDataSource)ds).UpdateExtractFile();
            }
        }

        private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e)
        {
            DashboardToolbarItem itemUpdate = new DashboardToolbarItem(
                (args) => UpdateExtract())
            {
                Caption = "Update Extract Data Source",
            };
            e.Items.Add(itemUpdate);

            DashboardToolbarItem itemSave = new DashboardToolbarItem(
                (args) => CreateExtractAndSave())
            {
                Caption = "Create Extract Data Source",
            };
            e.Items.Insert(0,itemSave);
        }
    }
}