This is a migrated thread and some comments may be shown as answers.

CSV Export: order of fields?

12 Answers 836 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark DeMichele
Top achievements
Rank 1
Mark DeMichele asked on 07 Dec 2009, 08:23 PM
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

12 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 08 Dec 2009, 07:23 AM
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.
0
Dan A
Top achievements
Rank 1
answered on 10 Mar 2011, 05:19 PM
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?


0
Steve
Telerik team
answered on 16 Mar 2011, 11:57 AM
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!
0
Dan A
Top achievements
Rank 1
answered on 16 Mar 2011, 02:30 PM
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?

0
Steve
Telerik team
answered on 21 Mar 2011, 11:30 AM
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
0
Fran
Top achievements
Rank 1
answered on 19 Dec 2013, 05:23 PM
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.
0
KS
Top achievements
Rank 1
answered on 21 Dec 2013, 12:51 PM
Hi,

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

-KS
0
Ben
Top achievements
Rank 2
answered on 29 Jan 2014, 10:25 PM
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());









0
Luke
Top achievements
Rank 1
answered on 05 Sep 2017, 11:38 PM

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.

0
Luke
Top achievements
Rank 1
answered on 06 Sep 2017, 02:18 PM

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.

0
Luke
Top achievements
Rank 1
answered on 06 Sep 2017, 02:19 PM

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.

0
Ari
Top achievements
Rank 1
answered on 26 Mar 2019, 10:19 AM

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

Tags
General Discussions
Asked by
Mark DeMichele
Top achievements
Rank 1
Answers by
Steve
Telerik team
Dan A
Top achievements
Rank 1
Fran
Top achievements
Rank 1
KS
Top achievements
Rank 1
Ben
Top achievements
Rank 2
Luke
Top achievements
Rank 1
Ari
Top achievements
Rank 1
Share this question
or