I have the following function that reads data from a remote csv file and does some processing on it before displaying it on a datatable.
function loadGrid()
{
link='{{ url("thecsvfile") }}/'+$('#class-id').val();
Papa.parse(link, {
download: true,withCredentials: true,header:true,
step: function(results, parser) {
//.... process the data row by row
cleanDataForGrid(results.data);
},
complete:function()
{
table =$('#the-grid').DataTable({
responsive: true,
destroy: true,
'bProcessing': true,
paging: false,
searching: false,
info:false,
scrollCollapse:true,
'columnDefs': [{
'targets': 0,
'searchable':false,
'orderable':false,
'width':'1%',
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" class="the_check">';
},
}],
});
updateDownloaded();
}
});
}
It currently works well, the problem is that when the CSV file has many rows, it takes a long time to load and at times the browser hangs or crashes. Is there a way we can get the number of rows first, if the file has more than X rows avoid the download completely? if I could get such an implementation where only the row count is returned.
function getRows()
{
var rowcount= Papa.parse(link, {download: false});
if(rowcount<50001) loadGrid();
}
Is it possible to have such an implementation?