Export PDF / CSV

I want to export pdf of a table , having 15 columns. Run time when click on PDF , Ask from user for Column selection which column should be in pdf  like check box selection.  If user select 10 column out of 15 then pdf generate for 10 columns . How it can be Possible.
Thanks in advance.

8 Replies 1 reply marked as answer

DM Dhivyabharathi Mohan Syncfusion Team February 10, 2021 12:41 PM UTC

Hi Muhammad, 
 
Can you please let us know which EJ2 component you are using to export the pdf of a table? It will be helpful for us to investigate further and provide details. 
 
Regards, 
Dhivya. 



MA Muhammad Arhum Saleem February 10, 2021 04:50 PM UTC

Yeah sure, i am using Grid .


TS Thiyagu Subramani Syncfusion Team February 12, 2021 12:50 AM UTC

Hi Muhammad, 

Thanks for your update. 

We can achieve this requirement by using getSelectedColumnsUid and getColumnByUid methods in toolbarClick event. In this toolbarClick event we get the all selected column’s Uids and defined this column definitions to the Grid before exporting PDF. Please refer to the below code and sample link. 


this.selectionOptions = { allowColumnSelection: true, type: 'Multiple' }; 
  
toolbarClick(args: any): void { 
    if (args.item.id === 'Grid_pdfexport') { 
     this.refreshCol = (this.grid as any).columns; 
      if (this.grid.getSelectedColumnsUid().length > 0) { 
        var col = []; 
                for (var i = 0; i < this.grid.getSelectedColumnsUid().length; i++) { 
          col.push(this.grid.getColumnByUid(this.grid.getSelectedColumnsUid()[i])) 
        } 
        (this.grid as any).columns = col; 
      } 
      this.grid.pdfExport(); 
    } 
  } 
  pdfExportComplete(args) { 
    (this.grid as any).columns = this.refreshCol;  
  } 



Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 


Marked as answer

MA Muhammad Arhum Saleem March 3, 2021 01:39 PM UTC

this is not same as i mention my query.

again , my query is .
when click on PDF button on toolbar , ask user which column will be add in PDF export then check that column and those columns which are not check will not be export in PDF file.. is it possible ?

Attachment: PDF_4d22a0e0.zip


TS Thiyagu Subramani Syncfusion Team March 5, 2021 12:19 AM UTC

Hi Muhammad, 

Sorry for the inconvenienced and thanks for your update. 

In previous update we have exported specific (selected) columns using our allowColumnSelection property. By default allowColumnSelection property used to select the columns in Grid. Selected columns are pushed to the empty array and defined to the grid Columns before exporting PDF. Please refer to the below video demonstration for more reference. 



Likewise you can check/select  the specific columns as per your needs and then move this selected columns to the grid columns like below code in toolbar click event. 

toolbarClick(args: any): void { 
    if (args.item.id === 'Grid_pdfexport') { 
      this.refreshCol = (this.grid as any).columns;  // initially store the grid columns in variable   
      if (this.grid.getSelectedColumnsUid().length > 0) { 
        var col = []; // create empty array 
        //Push your specific columns to the empty array 
        for (var i = 0; i < this.grid.getSelectedColumnsUid().length; i++) { 
          col.push(this.grid.getColumnByUid(this.grid.getSelectedColumnsUid()[i])) 
        } 
        // Assign pushed columns to the grid columns. 
        (this.grid as any).columns = col;  
      } 
      this.grid.pdfExport(); 
    } 
  } 



Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 



MA Muhammad Arhum Saleem March 10, 2021 10:15 AM UTC

Thank you for you response. I appreciate your effort. I have seen your demo video. i have applied your suggested code but getting an error.

"Property 'getSelectedColumnsUid' does not exist on type 'GridComponent'."


MA Muhammad Arhum Saleem March 10, 2021 11:21 AM UTC

this is error image.

Attachment: error_ba9db3aa.zip


TS Thiyagu Subramani Syncfusion Team March 11, 2021 04:53 PM UTC

Hi Muhammad, 

Thanks for your update. 

Based on your shared information we suspect the your reported issue may occurred due to the type definition. To achieve this requirement we suggest to use this.grid type as any like below. 


export class AppComponent { 
  public data: Object[] = []; 
  @ViewChild('grid', { static: true }) 
  public grid: GridComponent; 

---------------------------------------------- 
toolbarClick(args: any): void { 
    if (args.item.id === 'Grid_pdfexport') { 
      this.refreshCol = (this.grid as any).columns; 
      if ((this.grid as any).getSelectedColumnsUid().length > 0) { 
        var col = []; 
        for (var i = 0; i < (this.grid as any).getSelectedColumnsUid().length; i++) { 
          col.push(this.grid.getColumnByUid((this.grid as any).getSelectedColumnsUid()[i])) 
        } 
        (this.grid as any).columns = col; 
      } 
      this.grid.pdfExport(); 
    } 
  } 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 


Loader.
Up arrow icon