Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to export specific columns #1567

Closed
catfireparty opened this issue Dec 12, 2016 · 15 comments
Closed

Ability to export specific columns #1567

catfireparty opened this issue Dec 12, 2016 · 15 comments
Assignees
Labels
Type: New Feature Issue contains a new feature or new component request
Milestone

Comments

@catfireparty
Copy link

catfireparty commented Dec 12, 2016

I'm submitting a ...

[ x] feature request

I'd like the capability to export only selected columns from the DataTable.

e.g. dt.exportCSV(['columnTwo', 'columnFour'])

As it currently stands, it is impossible to select only the content of a single column for cut and paste, custom export would solve this in lieu of cell selection (and probably be easier to implement)

@pchristou
Copy link

@cagataycivici any plans on including something like this in a future release? I checked the roadmap and the only thing I saw related to export was "More export options like pdf and excel"

@pchristou
Copy link

Any update on this?

@cagataycivici cagataycivici changed the title [DataTable] Customisable Export Ability to export specific columns Jun 17, 2017
@cagataycivici cagataycivici added the Type: New Feature Issue contains a new feature or new component request label Jun 17, 2017
@cagataycivici cagataycivici modified the milestones: 4.1.0, 4.1.1 Jun 17, 2017
@cagataycivici
Copy link
Member

Planned for 4.1.1.

@kenisteward
Copy link

kenisteward commented Jun 22, 2017

@cagataycivici @jdpearce

Just to give info on my research of the component I'll lay this here. You can currently actually say which columns you want to export but it is slightly hacky (in my opinion) and definitely not recorded in the docs.

As you can see here
https://github.com/primefaces/primeng/blob/master/src/app/components/datatable/datatable.ts#L2137

the exportCsv function is base don the data table and specifically makes sure you have data AND a column with the FIELD property that is truthy (e.g. not null / undefined /empty string).

Because of this you can actually do something sneaky and say

in html

    <p-dataTable #dt [value]="data" exportFilename="data-objects">
      <p-header>
          <button type="button" pButton icon="fa-download" iconPos="left" label="Download CSV" (click)="export(dt)"></button>
      </p-header>
      <p-column *ngFor="let col of cols" [hidden]="col.hide" [sortable]="col.sortable" [field]="col.field [header]="col.header">
      </p-column>
    </p-dataTable>

in component

  public export(e: DataTable) {
     // store the columns you want to not export
    const hiddenColumns: any[] = [];
    e.columns.forEach((c) => {
       // search for whatever criteria you care for.  in my use case if the column is hidden i don't want to export that data
      if (c.hidden === true ) {
        hiddenColumns.push({field: c.field, col: c});
        c.field = '';
      }
    });

    e.exportCSV();
    // restore their fields so databinding and such still works in the future
    hiddenColumns.forEach((hc) => {
      hc.col.field = hc.field;
    });
  }

so instead of just calling dt.exportCSV() I've done some pre processing the datatable's data that it uses in the export function.

What would probably be preferable is there are API settings that hook into this function that only show fields based on either callback criteria or setting criteria. But this works fine currently.

@pantonis
Copy link
Contributor

Any news on this feature?

@cagataycivici
Copy link
Member

Planned for 4.1.1

@pantonis
Copy link
Contributor

Thanks

@cagataycivici cagataycivici modified the milestone: 4.1.1 Jul 19, 2017
@pantonis
Copy link
Contributor

Was this implemented in 4.1.1?

@Mrtcndkn
Copy link
Contributor

No, We rescheduled it for another release 4.1.2

Regards

@kenisteward
Copy link

kenisteward commented Jul 20, 2017 via email

@pantonis
Copy link
Contributor

@kenisteward although it works is not ideal

@kenisteward
Copy link

kenisteward commented Jul 20, 2017 via email

@pantonis
Copy link
Contributor

@Mrtcndkn did you implement it in 4.1.2?

@saunandrea
Copy link

saunandrea commented Feb 27, 2019

Is this a feature now? I haven't been able to find the documentation.

Update: noticed the link to the check-in, got it.
@Input() exportable: boolean = true;

so for example if anyone else finds their way here:

this.cols = [
      { field: "ID", header: "Id", exportable: true },

@pantonis
Copy link
Contributor

@saunandrea exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

No branches or pull requests

7 participants