diff --git a/papaparse.js b/papaparse.js index ed84bc3..131a6d6 100644 --- a/papaparse.js +++ b/papaparse.js @@ -709,6 +709,8 @@ _results = new Parser(_config).parse(input); return processResults(); + if (_config.preview && _config.header) + _config.preview++; // to compensate for header row }; function processResults() diff --git a/tests/test-cases.js b/tests/test-cases.js index 4811c62..49b512d 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -413,6 +413,16 @@ var PARSE_TESTS = [ errors: [] } }, + { + description: "Preview with header row", + notes: "Preview is defined to be number of rows of input not including header row", + input: 'a,b,c\r\nd,e,f\r\ng,h,i\r\nj,k,l', + config: { header: true, preview: 2 }, + expected: { + data: [{"a": "d", "b": "e", "c": "f"}, {"a": "g", "b": "h", "c": "i"}], + errors: [] + } + }, { description: "Keep empty rows", input: 'a,b,c\r\n\r\nd,e,f',