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

Export Buttons #1372

Closed
manusimon opened this issue Aug 10, 2023 · 2 comments
Closed

Export Buttons #1372

manusimon opened this issue Aug 10, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@manusimon
Copy link

It would be great having optional buttons for exporting data from the table in PDF, CSV...

@tevosouza
Copy link

hello @manusimon!
I hope that u are fine!

i'm trying to implement a plugin that can export the data, its earlier yet and i can export data to JSON at the moment and have a few limitations, like:

  • If pagination is active, it can only export the current page
  • Not tested on server search or pagination yet

Follow my code (experimental)

@afshinm, can you let me know if i'm on "right" path?

import { h } from 'preact';
import { useSelector } from "gridjs";
import { download } from './actions'


export interface ExportedRowData
{
  rowindex: number;
  columns: ExportColumnData[]
}

export interface ExportColumnData
{
  index:number
  name: string;
  value: string 
}

export function ExportGrid() {

  const data = useSelector((state) => state.data);
  const header = useSelector((state) => state.header);

  function doExport() {

  const exported: ExportedRowData[] = [];
    
    if (data)    
      data.rows.forEach((r, i) => {
        
        exported.push({
          rowindex: i,
          columns: []
        });

        r.cells.map(x => x.data).forEach((x, ic) => {
          exported[i].columns.push(
            {
              index: i,
              name: header.columns[ic].name,
              value: x
            }
          )
        });
      });
    
    download(JSON.stringify(exported), 'exported.json', 'application/json')  
  }
  
  return (
    <input
      type={'button'}
      value='Export JSON'
      onClick={() => doExport()}
    />
  );

}

@stale
Copy link

stale bot commented Oct 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Oct 15, 2023
@stale stale bot closed this as completed Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants