CSV Export: order of fields?

13 posts, 0 answers
  1. Mark DeMichele
    Mark DeMichele avatar
    74 posts
    Member since:
    Oct 2005

    Posted 07 Dec 2009 Link to this post

    Hi there,

    Using the StaticText configuration option found in previous forum posts, I was able to successfully generate a CSV export without unnecessary text fields. However, I didn't see an option to change the order of the fields in the resultant CSV export. It seems that they're being generated in the order in which they are created (I could be wrong). Is there any way to customize the order in which text fields appear in a CSV export?

    Thanks,
    Mark
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 08 Dec 2009 Link to this post

    Hi Mark DeMichele,

    As explained in the Design Considerations for CSV Rendering help article: "The remaining report items appear as ordered in the parent’s item collection. Each item is then rendered to a column.". So the behavior you observe is by design and expected.

    Note that CSV does not respect visible/invisible sections and formatting and layout are also ignored. If you want a WYSIWYG exported file, please use the excel rendering extension.
    Otherwise, if you insist on using CSV, you would have to re-order the report items in the Report item's collection in the order in which you would like them to appear.

    Greetings,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Dan A
    Dan A avatar
    6 posts
    Member since:
    Aug 2009

    Posted 10 Mar 2011 Link to this post

    The posted response does not appear to be accurate (or may have changed with more recent versions of the reporting tool).

    The data source for my report is a stored procedure that looks like this:

    SELECT u.CustomerId, c.LastName, c.FirstName, c.EmailAddress, c.ServiceStartDate,  l.Title as ServiceLevel,
              s.Description as AccountStatus, u.LastLoginDate, max(e.SentDate) as SentDate
    FROM .... <removed unneeded from, joins, and where clauses>
            GROUP BY u.CustomerId, c.LastName, c.FirstName, c.EmailAddress, c.ServiceStartDate, l.Title, s.Description, u.LastLoginDate

    If I store the results of the above in a recordset the field order is the same as the select statement.  I also have the data displayed on my report in the exact same order.

    However, when I export to CSV the fields are re-ordered to:

          CustomerId, FirstName, LastMessageSentDate, EmailAddress, ServiceStartDate, AccountStatus, LastLoginDate, LastName, 
          ServiceType

    There are no other collections involved that I have implemented.  According the the answer in the previous post I would have expected the CSV order to match the results of the select statement but this is clearly not what is happening.

    Has this changed in a more recent version of Telerik Reporting?  Is there a newer, more precise way to specified the column order of the CSV output?


  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 16 Mar 2011 Link to this post

    Hello Dan,

    It seems you have misunderstood the previous reply. You would have to re-order the report items in the Report item's collection in the order in which you would like them to appear and not the items in the select statement.

    Kind regards,
    Steve
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. Dan A
    Dan A avatar
    6 posts
    Member since:
    Aug 2009

    Posted 16 Mar 2011 Link to this post

    This is still as clear as mud.  

    Since you underlined the report items and report item's collection (without hyperlinking to any relevant documentation) I guess there must be a collection somewhere on the report full of "items".  Looking at the report properties I can see many collections (filters, groups, parameters, etc) but none of them contain any items that contain data I want exported.

    I did a seach on your site in the Help/Reporting area for "report items" hoping for clarification.  There I can see that the items are things like textboxes, charts, panels, SqlDataSources, etc. However, there doesn't seem to be a reference on how to access the collection so I can reorder them.  A search for "report item collection" on your site yielded no useful results.

    How do I access the report items collection so I can reorder the items?

  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 21 Mar 2011 Link to this post

    Hello Dan,

    Generally reordering the report items' collection is mainly viable for the CSV format, and this information is available in the Design Considerations for CSV Rendering help article: "The remaining report items appear as ordered in the parent’s item collection. Each item is then rendered to a column."
    The first report item added to the report is added as first member of the report items' collection, the second report item is added as second member etc.
    So if you have not taken that into account when creating the report, you would have to manually reorder the items' collection in the InitializeComponent() method. For example if you have 3 TextBox items in the detail section you would have the following markup:

    this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {this.textBox1, this.textBox2, this.textBox3});

    If you want the value of textBox2 to be the first in the exported CSV file, you should change it accordingly:

    this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {this.textBox2, this.textBox1, this.textBox3});

    Regards,
    Steve
    the Telerik team
  7. Fran
    Fran avatar
    1 posts
    Member since:
    Dec 2013

    Posted 19 Dec 2013 Link to this post

    I found that accessing the Report Explorer and using the Send to Back - Bring to Front in the fields you want to reorder works like a Move Down/Up in a way. The problem is that it sends the field you choose all the way to the top or the bottom. I think it would be a nice feature if you modify this so we could reorder the fields in a more visual way instead of going to the code. Just saying.
  8. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2013 Link to this post

    Hi,

    Just perform the same operation for all item in the order you want to see them.

    -KS
  9. Ben
    Ben avatar
    6 posts
    Member since:
    Jul 2011

    Posted 29 Jan 2014 in reply to Dan A Link to this post

    We faced the same problem in 2014.  I implemented a workaround to remove/re-add all the items in order or location. There's no visual different but the CSV file is ordered correctly, for any report:

                var detailSection = report.Items.OfType<DetailSection>().FirstOrDefault();
                var items = detailSection.Items.OfType<ReportItem>().ToList();

                // Remove them, they might be in wrong order
                detailSection.Items.RemoveRange(items);

                // Re-order in terms of position, to ensure correct CSV exporting
                items = items.OrderBy(x => x.Location.X).ThenBy(x => x.Location.Y).ToList();

                // Add them again in order
                detailSection.Items.AddRange(items.Cast<ReportItemBase>().ToArray());









  10. Luke
    Luke avatar
    12 posts
    Member since:
    Jul 2008

    Posted 05 Sep 2017 in reply to Steve Link to this post

    Where do you put that code? 

     

    The comments around the InitializeComponent procedure warn that it should not be modified. I tried to reorder the controls there, but if I modify the report from the designer, all my were lost.

    I tried to add the code in the report after the InitializeComponent procedure is called, but it didn't make a difference with the ASCII file.

  11. Luke
    Luke avatar
    12 posts
    Member since:
    Jul 2008

    Posted 06 Sep 2017 in reply to Luke Link to this post

    Oh, I figured it out.

    The change needs to replace the existing AddRange code further down that InitializeComponent method.

    So even though the comment mentions "do not modify the contents of this method with the code editor", we go ahead and do so anyway because this is the only way to change the order of the controls.

    I noticed that after I made the change, the order of the controls at the top automatically changed to the new order I specified, so that's nice.

  12. Luke
    Luke avatar
    12 posts
    Member since:
    Jul 2008

    Posted 06 Sep 2017 in reply to Luke Link to this post

    I figured it out.

    The change needs to replace the existing AddRange code further down that InitializeComponent method.

    So even though the comment mentions "do not modify the contents of this method with the code editor", we go ahead and do so anyway because this is the only way to change the order of the controls.

    I noticed that after I made the change, the order of the controls at the top automatically changed to the new order I specified, so that's nice.

  13. Ari
    Ari avatar
    1 posts
    Member since:
    Jun 2012

    Posted 26 Mar Link to this post

    Hi all,

    I just came across this issue and fortunately could mange to find a solution, I use stand along report designer, in the Report explorer window click Report explorer tab then you can reorder it from the details section.

    Regards

    Ari

Back to Top