Whenever I attempt to download filter data in ng-table to CSV, I encounter an issue where a single row is being split into two rows.
The expected output should look like this
Row1 consists of three columns:
Item 1 | 12222-12228-14567-124568-18680-20940-18717-ABCDED-sdf_dsfsdf | X-Large
However, the actual result looks like this:
1st row
Item 1 | 12222-12228-14567-124568-18680-20940-18717-ABCDED-sdf_dsfsdf |
2nd row
X-Large
This discrepancy is causing confusion. Here is a snippet of my code:
var data = [{ "name": "Item 1", "color": "12222-12228-14567-124568-18680-20940-18717-ABCDED-aSFDasdf_sdfsdf_dsfsdf", "size": "X-Large" },
{ "name": "Item 2", "color": "Green", "size": "X-Large" },
{ "name": "Item 3", "color": "Green", "size": "X-Large" }];
$scope.downloadData = function (data){
var csv = $scope.JsonToCsv(data);
}
$scope.JsonToCsv = function(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) :objArray;
var str = '';
var line = '';
var head = array[0];
for (var index in array[0]) {
var value = index + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
line = line.slice(0, -1);
str += line + '\r\n';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
line += array[i][index] + ',';
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
I would greatly appreciate any assistance in identifying what might be causing this issue within my code. Thank you!