Skip to content
Snippets Groups Projects
Commit 14842cd4 authored by Javier Romero Castro's avatar Javier Romero Castro Committed by Alex Ioannidis
Browse files

csv: fix preview of small csv

parent 167998ae
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ import Papa from "papaparse"; ...@@ -18,6 +18,7 @@ import Papa from "papaparse";
} }
const URL = $("#app").attr("data-csv-source"); const URL = $("#app").attr("data-csv-source");
const fileSize = $("#app").attr("data-csv-size");
const maxRowsPerChunk = 50; const maxRowsPerChunk = 50;
const $tableHeader = $("#table-header"); const $tableHeader = $("#table-header");
const $tableBody = $("#table-body"); const $tableBody = $("#table-body");
...@@ -33,6 +34,11 @@ import Papa from "papaparse"; ...@@ -33,6 +34,11 @@ import Papa from "papaparse";
papaParser.resume(); papaParser.resume();
}); });
// If the RemoteChunkSize is bigger than the size of the file it fails with a 416
if (fileSize < Papa.RemoteChunkSize) {
Papa.RemoteChunkSize = fileSize
}
Papa.parse(URL, { Papa.parse(URL, {
download: true, download: true,
skipEmptyLines: true, skipEmptyLines: true,
......
...@@ -18,6 +18,7 @@ import Papa from "papaparse"; ...@@ -18,6 +18,7 @@ import Papa from "papaparse";
} }
const URL = $("#app").attr("data-csv-source"); const URL = $("#app").attr("data-csv-source");
const fileSize = $("#app").attr("data-csv-size");
const maxRowsPerChunk = 50; const maxRowsPerChunk = 50;
const $tableHeader = $("#table-header"); const $tableHeader = $("#table-header");
const $tableBody = $("#table-body"); const $tableBody = $("#table-body");
...@@ -33,6 +34,11 @@ import Papa from "papaparse"; ...@@ -33,6 +34,11 @@ import Papa from "papaparse";
papaParser.resume(); papaParser.resume();
}); });
// If the RemoteChunkSize is bigger than the size of the file it fails with a 416
if (fileSize < Papa.RemoteChunkSize) {
Papa.RemoteChunkSize = fileSize
}
Papa.parse(URL, { Papa.parse(URL, {
download: true, download: true,
skipEmptyLines: true, skipEmptyLines: true,
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %} {%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %}
{% block panel %} {% block panel %}
<div id="app" data-csv-source="{{ file.uri }}"> <div id="app" data-csv-source="{{ file.uri }}" data-csv-size="{{file.size}}">
<table class="ui selectable celled table unstackable"> <table class="ui selectable celled table unstackable">
<thead id="table-header"> <thead id="table-header">
</thead> </thead>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %} {%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %}
{% block panel %} {% block panel %}
<div id="app" data-csv-source="{{ file.uri }}"> <div id="app" data-csv-source="{{ file.uri }}" data-csv-size="{{file.size}}">
<table class="ui selectable celled table unstackable"> <table class="ui selectable celled table unstackable">
<thead id="table-header"> <thead id="table-header">
</thead> </thead>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment