Export a VirtualQueryableCollectionView does only export already loaded items

11 posts, 0 answers
  1. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    Hello,
    I want to export all the items from my collection but only those already loaded get exported.
    How can I export the full list of items?
    Do I need to use something like a RadDomainDataSource in which I tranfert the selectors from the current virtual view?
    How should I do to export all my data?
    Any exemple?
    Thanks a lot in advance,
    John.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2011 Link to this post

    Hello,

     You need to force load of all data if you want to export all of them - download the data and load them using the Load() method of the collection. 

    Greetings,
    Vlad
    the Telerik team
  3. DevCraft banner
  4. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    Hello Vlad,
    Thank you for your help.

    What if the collection is pretty big?
    Will the virtual collection still load the items by page?
    How do I force the loading of all the items?
    Just call Load() ? And I guess this will take some time...
    Do I have to pool somehow the view and wait until it has loaded all the items?
    How do I know alll the items have been loaded?

    I'm a bit lost...
    Would you have a sample handy? That would help a lot...

    Thanks a lot...
    John.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2011 Link to this post

    Hello,

     How the collection will load data in your case? Are you using ItemsLoading? Are you loading the data from a service? 

    All the best,
    Vlad
    the Telerik team
  6. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    I'm loading the view like that:
    private SoContext context = new SoContext();
     
    public History()
    {
        InitializeComponent();
     
        //DataContext = new VirtualHistoryDatacontext();
     
        var query = context.GetBeneficiaryOrderLinesHistoQuery().OrderBy(o => o.OdlID);
     
        var view = new VirtualQueryableCollectionView() { LoadSize = 10, VirtualItemCount = 100 };
        view.ItemsLoading += (s, e) =>
        {
            var queryToLoad = query.IncludeTotalCount(true).Sort(view.SortDescriptors).Where(view.FilterDescriptors).Skip(e.StartIndex).Take(e.ItemCount);
     
            context.Load<CustomerPresentationModel>(queryToLoad).Completed += (sender, args) =>
            {
                var lo = (LoadOperation)sender;
                if (lo.TotalEntityCount != -1 && lo.TotalEntityCount != view.VirtualItemCount)
                {
                    view.VirtualItemCount = lo.TotalEntityCount;
                }
     
                view.Load(e.StartIndex, lo.Entities);
            };
        };
         
        DataContext = view;
    }

    And then export like that:
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = extension;
    dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);
    dialog.FilterIndex = 1;
     
    if (dialog.ShowDialog() == true)
    {
        using (Stream stream = dialog.OpenFile())
        {
            GridViewExportOptions exportOptions = new GridViewExportOptions();
            exportOptions.Format = format;
            exportOptions.ShowColumnFooters = true;
            exportOptions.ShowColumnHeaders = true;
            exportOptions.ShowGroupFooters = true;
     
            try
            {
                grdHistory.Export(stream, exportOptions);
            }
            catch (Exception ex)
            {
                ErrorWindow error = new ErrorWindow("L'exportation a échoué : ", ex.Message);
                error.Show();
            }
        }
    }

    Thanks a lot for the fast reply. I really need this...
    John.
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2011 Link to this post

    Hi,

    You can load all data using Load<>() method of your context (SoContext) - indeed you may get communication problems if you have too much data on the server. 

    Best wishes,
    Vlad
    the Telerik team
  8. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    Indeed... That's why I used the virtual view...

    I have two problems... Load lot's of data and load only those corresponding to the current view selectors (sorting and filters). Can I use those selector as-is to load my context collection?
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2011 Link to this post

    Hi,

     Maybe it will be better in this case to export data on the server and download the result using Telerik Reporting.

    Regards,
    Vlad
    the Telerik team
  10. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 17 Feb 2011 Link to this post

    Ha yeah, I didn't think of that. Why not. Can I let my user sort, filter and group in the report?
    I mean let him choose dynamicaly on which column to sort etc?
  11. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 22 Feb 2011 Link to this post

    Hi John,

    It depends on your data and its presentation. If you're using the Table/Crosstab item, groups, sorting and filters are a bit more complicated to execute from end user point of view and we do not recommend doing this. The Report Designer does a great deal of work to simplify common tasks, but the underlying code is far from trivial especially when it comes to Crosstab report item, which is not a mere grid of cells and has a very complex internal structure.

    Greetings,
    Steve
    the Telerik team
  12. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 22 Feb 2011 Link to this post

    Hello Steve,
    Thank you for the link and the explanation.
    I think I'll try to go that way and we'll see where it goes...
    Thanks again,
    John.
Back to Top
DevCraft banner