Spreadsheet data.

Spreadsheet data.

james_james_ Posts: 5Questions: 0Answers: 0
edited September 2011 in General
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 ?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    yes. there are several hooks and callback functions that would allow you to do this. the best would probably be the fnRender, which returns a text string to use in place of the original data. If used in conjunction with bUseRendered: false, the sort mechanism will use the original data to sort (and search?) by.

    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I didn't add any rounding to decimal places, but you could add that, as well as commas for values over 1,000.

    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)
  • james_james_ Posts: 5Questions: 0Answers: 0
    Thank you I will have a go with that and see how I go :)
  • james_james_ Posts: 5Questions: 0Answers: 0
    So I ended up using the following code which is based on the above but has a bit more in the way of error checking

    [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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    in almost all computer applications, the definition of Kb is 1024 bytes (2^10 Bytes), and each successive label (Mb, Gb, Tb, etc) are 1024 * the previous. if you use 1000, you'll be quite off compared to your users' expectations. this is why I used div = 1024 in my example.

    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
  • james_james_ Posts: 5Questions: 0Answers: 0
    In the application I am using it in it is used to display sizes of disc/luns/file systems etc. And the users do prefer 1000 for this. I made it a variable so it was easy to change between the two ( as an aside they get grumpy when it looks like they have lost a petabyte because of the differences.... ). Thanks once more
This discussion has been closed.