npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vanilla-datatables-exportable

v0.0.9

Published

A Vanilla-DataTables extension to allow for exporting to various formats.

Downloads

34

Readme

Exportable

npm version license

A Vanilla-DataTables extension to allow for exporting to various formats.

NOTE: This extension is only compatable with v2.0.0 and above of Vanilla-DataTables.

DEMO


Install

Bower

bower install vanilla-datatables-exportable --save

npm

npm install vanilla-datatables-exportable --save

Browser

Grab the file from one of the CDNs and include them in your page:

<script src="https://unpkg.com/vanilla-datatables-exportable@latest/datatable.exportable.min.js" type="text/javascript"></script>

//or

<script src="https://cdn.jsdelivr.net/npm/vanilla-datatables-exportable@latest/datatable.exportable.min.js" type="text/javascript"></script>

You can replace latest with the required release number.

NOTE: Make sure the above js file is included AFTER the main Vanilla-DataTables js file.


Options

var datatable = new DataTable(myTable, {
    exportable: {
        // options go here
    }
});

| Option | Type | Default | Effect | |--------------------|------------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | type | string | "json" | The format to export to: json, csv or sql. | | download | boolean | true | Export the table data to chosen file format. Set to false to return a string. | | escapeHTML | boolean | true | Strip HTML from the exported data. | | filename | string | "datatable_export" | The filename for the downloaded file. | | skipColumns | array | undefined | A collection of column indexes to omit from the exported data. | | pages | number|array | undefined | A single page or collection of pages to export. All other pages will be omitted. | | lineDelimiter | string | "\n" | The line delimiter for CSV or text data. | | columnDelimiter | string | "," | The column delimiter for CSV or text data. | | includeHeadings | boolean | true | Set the first line of the CSV string as the table headings. | | tableName | string | "table" | The MySQL table name for SQL data. | | columnize | boolean | false | Format the text string into columns. | | paddingCharacter | string | " " | The character used to pad the columns when columnize is enabled. | | replacer | array|function | undefined | The JSON.stringify() replacer parameter. (More info). | | space | number|string | | The JSON.stringify() space argument. (More info). | | modal | boolean | true | Shows the print modal when calling the print() method. Set to false to just display a printable version. |


Public Methods

Each of the following methods accepts an optional Object of options as it's only parameter to configure the exporter on the fly. These options will override the global options set above.

Methods are called using the exportable property of the current Vanilla-DataTables instance:

datatable.exportable.methodName();

export(options)

Export with given options.

// Export to json string
datatable.exportable.export({
    type: "json",
});

You can also override global options:

// Export to json string
datatable.exportable.export({
    type: "json",
    download: false,
    space: 2
});

toText()

Export to plain text file.

datatable.exportable.toText();

// Export to json string
datatable.exportable.toText({ download: false });


// Columnize the data
datatable.exportable.toText({ columnize: true, paddingCharacter: " | " });

// before:
Conan the Barbarian|1982|Conan|
Conan the Destroyer|1984|Conan|
The Terminator|1984|T-800 / Terminator|
Red Sonja|1985|Kalidor|
Commando|1985|Colonel John Matrix|
Raw Deal|1986|Kaminsky|
Predator|1987|Major Alan "Dutch" Schaefer|
The Running Man|1987|Ben Richards|
Red Heat|1988|Captain Ivan Danko|
Twins|1988|Julius Benedict|
Total Recall|1990|Douglas Quaid / Hauser|
Kindergarten Cop|1990|Detective John Kimble|
Terminator 2: Judgment Day|1991|T-800|
Last Action Hero|1993|Jack Slater / Himself|Also executive producer

// after
Conan the Barbarian        | 1982 | Conan                       |                        
Conan the Destroyer        | 1984 | Conan                       |                        
The Terminator             | 1984 | T-800 / Terminator          |                        
Red Sonja                  | 1985 | Kalidor                     |                        
Commando                   | 1985 | Colonel John Matrix         |                        
Raw Deal                   | 1986 | Kaminsky                    |                        
Predator                   | 1987 | Major Alan "Dutch" Schaefer |                        
The Running Man            | 1987 | Ben Richards                |                        
Red Heat                   | 1988 | Captain Ivan Danko          |                        
Twins                      | 1988 | Julius Benedict             |                        
Total Recall               | 1990 | Douglas Quaid / Hauser      |                        
Kindergarten Cop           | 1990 | Detective John Kimble       |                        
Terminator 2: Judgment Day | 1991 | T-800                       |                        
Last Action Hero           | 1993 | Jack Slater / Himself       | Also executive producer

toJSON()

Export to JSON file.

datatable.exportable.toJSON();

// Export to json string
datatable.exportable.toJSON({ download: false });

toCSV()

Export to CSV file.

datatable.exportable.toCSV();

// Export to csv string
datatable.exportable.toCSV({ download: false });

toSQL()

Export to SQL file.

datatable.exportable.toSQL();

// Export to sql string
datatable.exportable.toSQL({ download: false });

print()

Print the table. This method will open a new window/tab and display a printable version of the table.

datatable.exportable.print();

Changelog

v0.0.9

  • Added toText() method to export to text file/string;
  • Allow formatting (padding) of text string to columns

v0.0.7

  • Allow export of headings in CSV strings (#1)
  • Allow HTML to be stripped (#1)

v0.0.6

  • Added destroy() method
  • Fix bug causing filename concatenation

v0.0.5

  • Fix incorrect filename reference

v0.0.4

  • Fix toCSV() method not returning string.

v0.0.3

  • Incorrect file names.

v0.0.2

  • Add modal option for print() method.

v0.0.1

  • Initial commit.

Copyright © 2017 Karl Saunders | MIT license