sideboard v0.6.0
Sideboard
Everything you need to set your tables right.
A "hack day" project from The Dallas Morning News.
The sideboard stands alone
sideboard is built to be a lean table-setting machine. It requires just one external dependency — Papa Parse — and uses ES6-native functions for the rest of its features.
Getting started
Sideboard is best used within an interactive or embed.
Installing and setting up Sideboard
Once you have your project created, run npm install sideboard.
- Sideboard depends on Font Awesome for some icons, so in your
index.htmlfile, be sure to include a call to Font Awesome. You can get the requiredlinktag here. - Sideboard also has specific styles, so be sure to import its styles. Add
@import '../../node_modules/sideboard/src/scss/styles';to yourstyles.scssfile. - Import Sideboard into your js:
import Sideboard from 'sideboard'; - Currently, Sideboard only supports csv. Place your csv file in your data folder.
Running Sideboard
Call Sideboard within your scripts.js file like so: window.sideboard = new Sideboard({});
The object passed to Sideboard has some required keys:
dataSource: An object that defines the source of the data. Has keys fortype(string), andurl(string).el: String with the id ('#' included) of the div where you want to draw your tableresultsPerPage: Integer specifying number of results per page of your tablefilters: An array of objects specifying what types of filters to use on which columns. Each filter object takes asourceField(string) key and atype(string) key.sourceFieldis the column header you want the filter to apply to,typeis the type of filter, expecting either a value ofsearchboxordropdown.New in version 0.3.9: You can also now specify a
customMatchFnproperty on filter configuration objects. This property should be a function which takes two arguments (the value of the row being tested and the value of the user's input, respectively) and returns either True or False depending on whether the row passes the filtering test.columns: An array of objects that defined thesourceField(a string of the column name), and apublicLabel( a string of how you want the column name to be displayed). Can also take a type ofintegerfor columns of numbers (not including percents or dollar figures). New in version 0.4.0: You can set a column to be unsortable by setting the sortable key tofalseon that column. Columns are sortable by default.
Example Sideboard call:
window.sideboard = new Sideboard({
dataSource: {
type: 'csv',
url: 'data/private-schools.csv',
},
el: '#sortable-table',
resultsPerPage: 20,
filters: [
{ sourceField: 'School Name', type: 'searchBox' },
{ sourceField: 'DistrictName', type: 'dropdown' },
],
columns: [
{ sourceField: 'School Name', publicLabel: 'School name' },
{ sourceField: 'DistrictName', publicLabel: 'District name', sortable: 'false' },
{ sourceField: 'low', publicLabel: 'Low grade' },
{ sourceField: 'high', publicLabel: 'High grade' },
{ sourceField: 'enrollment', publicLabel: 'Enrollment', type: 'integer' },
],
onInitialLoad: () => { pymChild.sendHeight(); },
})