CSV Data Sources in Blazor Pivot Table: A Groundbreaking Feature | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (203)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (65)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (81)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (897)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (39)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (501)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (381)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (323)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
CSV Data Sources in Blazor Pivot Table: A Groundbreaking Feature

CSV Data Sources in Blazor Pivot Table: A Groundbreaking Feature

In our 2020 Volume 2 release, the Blazor Pivot Table component has added support for comma-separated value (CSV) data sources. CSV is one of the most popular data sharing formats, primarily used in business and science applications. It is also considered a more compact format than JSON, as it is just half the size of JSON. As such, it helps reduce bandwidth usage while transferring data through a browser.

In the Blazor Pivot Table component, a CSV data source can be set as input in the following ways:

Let’s learn about them!

As a file from local storage

A CSV file can be retrieved from local storage using the File Uploader component. Once the file is uploaded, the contents will be converted to the format accepted by the Pivot Table and set as its data source.

Refer to the following code example.

[*.ts]

import { PivotView } from '@syncfusion/ej2-pivotview';
import { Uploader } from '@syncfusion/ej2-inputs';

// Step 1: Initiate the File Uploader.
let uploadObj: Uploader = new Uploader();
uploadObj.appendTo('#fileupload');
let input = document.querySelector('input[type="file"]');
// Step 2: Add the event listener which fires when the *.CSV file is uploaded.
input.addEventListener('change', function (e: Event) {
    // Step 3: Initiate the file reader.
    let reader: FileReader = new FileReader();
    reader.onload = function () {
        // Step 4: Getting the string output which is to be converted as string[][].
        let result: string[][] = (reader.result as string).split('\n').map(function (line) {
            return line.split(',');
        });
        let pivotObj: PivotView = new PivotView({
            dataSourceSettings: {
                // Step 5: The string[][] result to be bound as data source.
                dataSource: result,
                // Step 6: Set data source type as “CSV”.
                type: 'CSV',
                // Step 7: The appropriate report needs to be provided here.
            },
        });
        pivotObj.appendTo('#PivotTable');
    };
    reader.readAsText((input as any).files[0]);
});

As a file from remote storage

A CSV file can be uploaded to any server, and its HTTP or HTTPS link can then be set for the Pivot Table. Then, the Pivot Table will internally retrieve and convert the data to the required format for future processing.

Refer to the following code example.

[*.ts]

let pivotObj: PivotView = new PivotView({
    dataSourceSettings: {
        // URL for file hosted on remote server  needs to be placed here.
        url: 'https://cdn.syncfusion.com/data/sales-analysis.csv',
        // Set data source type as “CSV”.
        type: 'CSV',  
        // The appropriate report needs to be provided here.
    },
});

From a web service using “text/csv” MIME type

CSV data can be transferred from any web service to the Pivot Table component. Users just need to add the service URL to the Pivot Table, and the component will internally retrieve and convert the data to the format needed for future processing.

[*.ts]

let pivotObj: PivotView = new PivotView({
    dataSourceSettings: {
        // URL for file hosted on service  needs to be placed here.
        url: 'https://bi.syncfusion.com/productservice/api/sales',   
        // Set data source type as “CSV”.
        type: 'CSV',  
        // The appropriate report needs to be provided here.
    },
});

CSV: A robust format

As stated previously, the compact size of CSV is a great advantage when transferring large sets of data to the Pivot Table for quick processing and rendering. In the metrics given below, you can see the bandwidth timing of CSV compared to JSON while receiving data from a source.

Records countTime taken to retrieve data from source
JSONCSV
1k rows * 10 columns0.02s0.01s
5k rows * 10 columns0.06s0.03s
10k rows * 10 columns0.12s0.05s
100k rows * 10 columns0.6s0.3s

NOTE:

  1. The values might be different depending on network speed.
  2. The above estimates were made by retrieving data from a server through a downloadable link (either HTTP or HTTPS).
  3. After the data retrieval, the component rendering time is the same for both the CSV and JSON file types, which are 0.5 second, 1 second, 1.2 seconds, and 2.5 seconds respectively for the above-mentioned metrics. The virtual scrolling option was also enabled in this sample.

Conclusion

In this blog, we have seen the merits of the new CSV data source support in the Syncfusion Blazor Pivot Table. This groundbreaking support is available in our 2020 Volume 2 release. You can check out all the new features in our release notes and on the What’s New page.

Use this CSV support and increase your productivity!

For existing customers, the new version is available for download from the License and Downloads page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features. Also, try our samples from this GitHub location.

If you wish to send us feedback, please use the comments section below. You can also contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed