Spreadsheet data.
Spreadsheet data.
Is it possible to have the exported data different from the displayed data, for example I would like the displayed data to be say 250GB or 4TB but the spreadsheet data to be in bytes.
On the Mac atleast both the csv and xls are saved by default as csv.
Any "," in the data break the csv, would it be possible to escape them in the csv ?
On the Mac atleast both the csv and xls are saved by default as csv.
Any "," in the data break the csv, would it be possible to escape them in the csv ?
This discussion has been closed.
Replies
assuming column 4 is the file size:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
null,
null,
null,
null
{ // file size
"bUseRendered": false,
// "sClass": "yourFilesizeClass", // if you have a special css class for filesizes
"fnRender": function (oObj) {
value = oObj.aData[oObj.iDataColumn];
// value = Math.abs(parseInt(value)); // uncomment this to do some simple data checking
if (value < 1024) return value + "b"; // use Bytes up to 1Kb
value /= 1024;
if (value < 1024) return value + "Kb"; // use Kbytes up to 1Mb
value /= 1024;
if (value < 1024) return value + "Mb"; // use Mbytes up to 1Gb
value /= 1024;
if (value < 1024) return value + "Gb"; // use Gbytes up to 1Tb
value /= 1024;
return value + "Tb"; // else use Tbytes
}
},
]
} );
} );
[/code]
You could use other callbacks if you wanted to. fnRowCallback is called for every row drawn, giving you the row node, array of data, and a few other params. fnDrawCallback is called after all rows draw, no params but you could use Javascript/JQuery to go through
in CVS, if your commas are within a string surrounded by quotes, they will be fine (by any software that respects the quotes, that is)
[code]
render_fs_size = function (oObj) {
value = oObj.aData[oObj.iDataColumn];
value = value.replace (/[^\d]/g, '');
div=1000;
sign=""
value_f=parseInt(value);
if ( typeof(value_f) != "number" ) {
return "0 b" ;
}
if ( isNaN(value_f) ) {
return "0 b" ;
}
if ( value_f < 0 )
{
sign="-"
value_f=value_f*-1;
}
if (value_f < div) return sign + value_f + " b"; // use bytes up to 1Mb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Kb"; // use Kbytes up to 1Mb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Mb"; // use Mbytes up to 1Gb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Gb"; // use Gbytes up to 1Tb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Tb"; // use Tbytes up to 1Pb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Pb"; // use Pbytes up to 1Eb
value_f /= div;
if (value_f < div) return sign + value_f.toFixed(1) + " Eb"; // use bytes up to 1Zb
value_f /= div;
return sign + value_f.toFixed(1) + "Zb"; // Let's stop at Zb
}
[/code]
Any issue are obviously my own, thanks fbas
one exception: hard drive manufacturers like to use 1000 as their base because it makes their drives seem larger than they are. 1 Tb (base 1000) is much less than 1 Tb (base 1024) [base 1000 is only 931.32 Gb]
base 1000 usage is proper SI, but very misleading when used in computer applications which expect base 1024