Download
User Rating: 4.7/5 ( 1 votes)
Table to JSON is a jQuery plugin that converts an HTML Table into a javascript object. Great for working with user-editable tables or accessing output from 3rd party tools.
Features
-
Automatically finds column headings.
-
Override found column headings by using data-override="overridden column name".
-
Always uses first row as column headings regardless of th and td tags.
-
Define headings using the headings option when a table doesn't have any specified headings.
-
Override cell values column names by using data-override="new value".
-
Ignorable columns.
-
Not confused by nested tables.
-
Works with rowspan and colspan
Source: lightswitch05.github.io
1. INCLUDE JS FILES
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="javascripts/jquery.tabletojson.min.js"></script>
2. HTML
<table id='example-table'>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th data-override="Score">Points</th></tr>
</thead>
<tbody>
<tr>
<td>Jill</td>
<td>Smith</td>
<td data-override="disqualified">50</td></tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td></tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td></tr>
<tr>
<td>Adam</td>
<td>Johnson</td>
<td>67</td></tr>
</tbody>
</table>
3. JAVASCRIPT
var table = $('#example-table').tableToJSON();
4. OPTIONS
-
ignoreColumns
-
Array of column indexes to ignore.
-
Type: Array
-
Default: []
-
onlyColumns
-
Array of column indexes to include, all other columns are ignored. This takes presidence over ignoreColumns when provided.
-
This takes presidence over ignoreColumns when both are provided.
-
Type: Array
-
Default: null - all columns
-
ignoreHiddenRows
-
Boolean if hidden rows should be ignored or not.
-
Type: Boolean
-
Default: true
-
headings
-
Array of column headings to use. When supplied, all table rows are treated as values.
-
Type: Array
-
Default: null
-
allowHTML
-
Boolean if HTML tags in table cells should be preserved
-
Type: Boolean
-
Default: false