akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 877 forks source link

Export screen data to XLS #730

Closed rsmartins78 closed 5 years ago

rsmartins78 commented 6 years ago

Is there any way to export screen data (with and without applied filters) to XLS or CSV file?

I'm migrating an old application from ExtJS3.4 to Angular, however I'm still learning Angular.

I was able to create my table with ng2-smart-table successfully, but I'm thinking how to export the data, because in the old tool, I made a call to an export.php that makes a query in the database and exports to XLS.

Thank you for your attention.

Sorry for my English.

Anujmoglix commented 6 years ago

Hey , use this npm install --save angular5-csv for export , I am using this and working fine

rsmartins78 commented 6 years ago

As I said, I'm still learning. So in the example presented, I can create a button that calls a function and in this function I'll put this "new Angular5Csv(data, 'My Report');" ??

Thank you for the attention and sorry for my english.

Anujmoglix commented 6 years ago

i did like this

    public downloadCsv() {
      const options = {
            fieldSeparator: ',',
            quoteStrings: '"',
            decimalseparator: '.',
            showLabels: true,
            showTitle: true,
            headers: ['ID', 'Seller Name', 'User Name', 'Email','Date']
        };
        this.MYfile = new Angular5Csv(this.data, 'Report', options);
    }
rsmartins78 commented 6 years ago

Thank you, I'll test it

dylantientcheu commented 5 years ago

To add on what @Anujmoglix said; You can also get it done this way after having declared table source with LocalDataSource type:

downloadCSV() {
    const options = {
      fieldSeparator: ',',
      quoteStrings: '"',
      decimalseparator: '.',
      showLabels: true,
      showTitle: true,
      useBom: true,
      headers: [
        'id',
        'numero',
        'objet',
      ],
    };
    this.source.getAll().then(data => {
      new Angular5Csv(data, 'report', options);
    })
  }
RichardLamb commented 3 years ago

FYI If you want to export just filtered data, then use this.source.getFilteredAndSorted()