Skip to content

Commit

Permalink
Skip columns where headers are not present
Browse files Browse the repository at this point in the history
this fix address issue with data looks like:
```
{
  "Name": "Alex",
  "":"",
 "Type": "human"
 "":"" 
  },
```
Usually this is a problem with tables where column with buttons(edit/delete) has no header and is useless.
  • Loading branch information
noma4i committed Jun 8, 2017
1 parent 550cd3d commit 30fd2e4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/jquery.tabletojson.js
Expand Up @@ -21,7 +21,11 @@
var notNull = function(value) {
return value !== undefined && value !== null;
};


var notEmpty = function(value) {
return value !== undefined && value.length > 0;
};

var ignoredColumn = function(index) {
if( notNull(opts.onlyColumns) ) {
return $.inArray(index, opts.onlyColumns) === -1;
Expand All @@ -35,7 +39,9 @@
// when ignoring columns, the header option still starts
// with the first defined column
if ( index < keys.length && notNull(value) ) {
result[ keys[index] ] = value;
if (notEmpty(keys[index])){
result[ keys[index] ] = value;
}
index++;
}
});
Expand Down

0 comments on commit 30fd2e4

Please sign in to comment.