diff --git a/README.md b/README.md index 932dd51..8dd5e5f 100755 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@ # sheetsee-tables -Sheetsee,js uses this module to make tables. With this module you can create tables with your spreadsheet data that are sortable, searchable and paginate-able. +Sheetsee.js uses this module to make tables. With this module you can create tables with your spreadsheet data that are sortable, searchable and paginate-able. You'll need a placeholder `
` in your html, a ` @@ -134,5 +136,5 @@ _JavaScript_ ``` -_[View Demo](http://jlord.us/sheetsee.js/demos/demo-table.html)_ -_[Visit Site](http://jlord.us/sheetsee.js)_ +_Local Demo_: run `npm run bfy`, then open `test/index.html`. +_[Visit Site](https://jlord.us/sheetsee.js)_ diff --git a/docs/step-by-step.md b/docs/step-by-step.md new file mode 100644 index 0000000..6e4c7fb --- /dev/null +++ b/docs/step-by-step.md @@ -0,0 +1,108 @@ +# Step-by-step table setup + +This guide shows the smallest reliable path from spreadsheet-style data to a searchable, sortable, paginated table. + +## 1. Add a table placeholder + +Add an input for filtering, a clear link, and an empty div where the table will be rendered. + +```html + +Clear +
+``` + +The clear link must use `class="clear"`. Do not include the dot in the class attribute. + +## 2. Add a Mustache template + +Place a template script on the same page. By default, the template id must match the table div id with `_template` appended. + +```html + +``` + +Use `class="tHeader"` on any column header that should be sortable. + +For sorting, Sheetsee removes spaces and punctuation from the header text and uses the result as the data key. For example, `Place Name` sorts by `PlaceName`. + +## 3. Prepare data + +Sheetsee expects an array of objects. The keys should match the sortable header names after spaces are removed. + +```js +var data = [ + { + City: "Oakland", + PlaceName: "Lake Merritt", + Year: "1870", + Image: "lake.jpg" + }, + { + City: "San Francisco", + PlaceName: "Sutro Baths", + Year: "1896", + Image: "sutro.jpg" + } +] +``` + +If the data comes from Tabletop.js or another spreadsheet loader, call Sheetsee after that loader has returned the rows. + +## 4. Build the table + +Call `Sheetsee.makeTable()` after the DOM and data are ready. Call `Sheetsee.initiateTableFilter()` if you added a filter input. + +```html + +``` + +If `templateID` is omitted, Sheetsee looks for `siteTable_template` because `tableDiv` is `#siteTable`. + +## 5. Test locally + +The repository includes a working browser demo in `test/index.html`. + +```bash +npm install +npm run bfy +``` + +Then open `test/index.html` in a browser. The demo should let you filter by `cat`, clear the filter, sort by `Rating`, and move between pages. + +## Troubleshooting + +- Blank table: confirm the template id matches `templateID`, or matches `tableDiv` plus `_template`. +- Sorting error: confirm each sortable header maps to a real data key, such as `Place Name` -> `PlaceName`. +- Clear button does nothing: confirm the link uses `class="clear"`. +- Filter does nothing: confirm `filterDiv` includes the hash, for example `#siteTableFilter`. diff --git a/test/browserify.js b/test/browserify.js index eaca8ed..e0dafa2 100644 --- a/test/browserify.js +++ b/test/browserify.js @@ -1,6 +1,7 @@ var fs = require('fs') +var path = require('path') var browserify = require('browserify') -browserify(__dirname + '/set.js') +browserify(path.join(__dirname, 'set.js')) .bundle() - .pipe(fs.createWriteStream(__dirname + '/sheetsee.js')) + .pipe(fs.createWriteStream(path.join(__dirname, 'sheetsee.js'))) diff --git a/test/data.js b/test/data.js index 337ddbb..da9c74e 100644 --- a/test/data.js +++ b/test/data.js @@ -1,27 +1,29 @@ -var data = [ - { - "Animal": "Cat", - "Name": "Liza", - "Rating": "10" - }, - { - "Animal": "Dog", - "Name": "Boo", - "Rating": "9" - }, - { - "Animal": "Dog", - "Name": "Sam", - "Rating": "10" - }, - { - "Animal": "Cat", - "Name": "Snowy", - "Rating": "4" - }, - { - "Animal": "Cat", - "Name": "Trisana", - "Rating": "7" - } +/* global window */ + +window.data = [ + { + Animal: 'Cat', + Name: 'Liza', + Rating: '10' + }, + { + Animal: 'Dog', + Name: 'Boo', + Rating: '9' + }, + { + Animal: 'Dog', + Name: 'Sam', + Rating: '10' + }, + { + Animal: 'Cat', + Name: 'Snowy', + Rating: '4' + }, + { + Animal: 'Cat', + Name: 'Trisana', + Rating: '7' + } ]