Skip to content

Commit

Permalink
Storage & Build widget: pass "null" to $.parseJSON as a fallback. Fixes
Browse files Browse the repository at this point in the history
#586

Also change build widget example code to use dataType:"text" for csv data
  • Loading branch information
Mottie committed Jan 18, 2015
1 parent bbaf908 commit a50f555
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/example-widget-build-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ <h3>Notes</h3>
<ul>
<li>(<code>build_headers</code> &amp; <code>build_footers</code>) have been added allowing customizing the headers and/or footers.</li>
<li>The <code>rows</code> option sets the number of headers rows to include from the data source. <strong>Zero is not an option</strong> since tablesorter requires a thead in place before it will initialize.</li>
<li>The <code>classes</code> array sets each header cell (<code>th</code>) class name.</li>
<li>The <code>classes</code> array sets each header cell (<code>th</code>) class name.</li>
<li>The <code>text</code> array within these options will override any text obtained from the data source.</li>
<li>The <code>widths</code> array, only in the <code>build_headers</code> option, sets column widths by building <code>&lt;col&gt;</code> elements within a <code>&lt;colgroup</code>.</li>
<li>Adding class names to the tbody rows or cells isn't easily accomplished, but you can bind to the build complete event (<code>'tablesorter-build-complete'</code>) and add them yourself.</li>
Expand Down Expand Up @@ -383,7 +383,7 @@ <h3>Notes</h3>
<ul>
<li>(<code>build_headers</code> &amp; <code>build_footers</code>) have been added allowing customizing the headers and/or footers.</li>
<li>The <code>rows</code> option sets the number of headers rows to include from the data source. <strong>Zero is not an option</strong> since tablesorter requires a thead in place before it will initialize.</li>
<li>The <code>classes</code> array sets each header cell (<code>th</code>) class name.</li>
<li>The <code>classes</code> array sets each header cell (<code>th</code>) class name.</li>
<li>The <code>text</code> array within these options will override any text obtained from the data source.</li>
<li>The <code>widths</code> array, only in the <code>build_headers</code> option, sets column widths by building <code>&lt;col&gt;</code> elements within a <code>&lt;colgroup</code>.</li>
<li>Adding class names to the tbody rows or cells isn't easily accomplished, but you can bind to the build complete event (<code>'tablesorter-build-complete'</code>) and add them yourself.</li>
Expand Down Expand Up @@ -502,7 +502,7 @@ <h3>Javascript</h3>
widgetOptions: {
// *** build widget core ***
build_type : 'csv',
build_source : { url: 'assets/csv.txt', dataType: 'html' },
build_source : { url: 'assets/csv.txt', dataType: 'text' },
build_headers : {
widths : ['30%', '50%', '20%'] // set header cell widths
}
Expand Down
4 changes: 2 additions & 2 deletions docs/js/demo-build-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(function(){
var rows = data.split(';');
return $.each(rows, function(i,cells) {
// similar to using rows[i] = cells.split(',') but the splitCSV script
// doesn't split the cell if the separator (comma) is within quotes
// doesn't split the cell if the separator (comma) is within quotes
rows[i] = $.tablesorter.buildTable.splitCSV(cells, ',');
});
}
Expand Down Expand Up @@ -94,7 +94,7 @@ $(function(){
widgetOptions: {
// *** build widget core ***
build_type : 'csv',
build_source : { url: 'assets/build.txt', dataType: 'html' },
build_source : { url: 'assets/build.txt', dataType: 'text' },
build_headers : {
widths : ['30%', '50%', '20%'] // set header cell widths
}
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.tablesorter.widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ ts.storage = function(table, key, value, options) {
// *** get value ***
if ($.parseJSON) {
if (hasLocalStorage) {
values = $.parseJSON(localStorage[key] || '{}');
values = $.parseJSON(localStorage[key] || 'null') || {};
} else {
// old browser, using cookies
cookies = document.cookie.split(/[;\s|=]/);
// add one to get from the key to the value
cookieIndex = $.inArray(key, cookies) + 1;
values = (cookieIndex !== 0) ? $.parseJSON(cookies[cookieIndex] || '{}') : {};
values = (cookieIndex !== 0) ? $.parseJSON(cookies[cookieIndex] || 'null') || {} : {};
}
}
// allow value to be an empty string too
Expand Down
2 changes: 1 addition & 1 deletion js/widgets/widget-build-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var ts = $.tablesorter = $.tablesorter || {},
return bt.html( table, d, wo );
}
try {
d = $.parseJSON(d);
d = $.parseJSON(d || 'null');
if (d) {
// valid JSON!
return bt.object( table, d, wo );
Expand Down

0 comments on commit a50f555

Please sign in to comment.