Tuesday, November 10, 2015

Package of the Month: DT

Sometimes you have the need to email someone a dataset for them to analyze. In the past, I always sent an Excel workbook with a bit of formatting. This always takes a bit of time, and never looks as pretty as you want it to. Plus, Excel workbooks just don't work well on cell phones. I've found a nice package that is a wrapper for the DataTables plug-in for jQuery. This package allows me to email out a html file for people to review and analyze as they see fit. Below are just a sample of options I've found handy.

First, let's load in some data and view the default look of the table.


By default, we can search the table and sort individual columns. Let's change the page length to 20 and remove row names.


Sometimes you want to set the default sort order. Here we sort the table by weight descending.


One really cool extension for DataTables allows you to drag and drop columns into a custom order as you explore the data. Combine this with the ability to hide columns really helps you customize a look for the table.


Finally, let's combine all of these tables and save it to an html file to email out.



Note, to get this to look somewhat nice on my blog, I automatically hide several columns.