Apply mask to cell values

Apply mask to cell values

dcd4u2dcd4u2 Posts: 5Questions: 0Answers: 0
edited September 2011 in General
Hi,

Let me say I found jQuery and DataTables a few days ago and i'm surprised with all this, soo i'm simply a noob. But untill now... let me say this is scripting at state of art.

I need to apply a javascript function to mascarade each cell in a coll, let say I want to auto change the value from '1000' to '$1.000' or '1,000 €'.
This function is done and working in javascript what I don't know is how to use it in DataTables.

My Table is:

[code]
$(document).ready(function() {
var oTable = $('#table_6_2').dataTable( {
"bProcessing": true,
"sAjaxSource": 'modules.php?name=teste5&opt=table_6_2&reg='+base64_encode(array2string(window.registos)),
"bServerSide": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": true,
"aoColumns": [
{ "mDataProp": "vendas_facturas_linhas[sdo]" },
{ "mDataProp": "vendas_facturas_linhas[linha]" },
{ "mDataProp": "vendas_facturas_linhas[factura]" },
{ "mDataProp": "vendas_facturas_linhas[mercadoria]" },
{ "mDataProp": "vendas_facturas_linhas[designacao]" },
{ "mDataProp": "vendas_facturas_linhas[quantidade]" },
{ "mDataProp": "mercadorias_unidades_venda[designacao_abrev]" },
{ "mDataProp": "vendas_facturas_linhas[preco_venda]" },
{ "mDataProp": "vendas_facturas_linhas[taxa_desconto_comercial]" },
{ "mDataProp": "vendas_facturas_linhas[tipo_iva_venda]" },
{ "mDataProp": "vendas_facturas_linhas[taxa_iva]" },
{ "mDataProp": "vendas_facturas_linhas[total_iva]" },
{ "mDataProp": "vendas_facturas_linhas[total_bruto]" }
],
"fnDrawCallback": function() {
?????????????;
}
} );
} );

[/code]

If you can help please do. Much apreciated.

Replies

  • dcd4u2dcd4u2 Posts: 5Questions: 0Answers: 0
    Well, I think I found...

    [quote]
    var oTable = $('#table_6_2').dataTable( {
    "bProcessing": false,
    "sAjaxSource": 'modules.php?name=teste5&opt=table_6_2&reg='+base64_encode(a2s(window.registos)),
    "bServerSide": true,
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true,
    "bInfo": false,
    "bAutoWidth": true,
    "aoColumns": [
    { "mDataProp": "vendas_facturas_linhas[sdo]" },
    { "mDataProp": "vendas_facturas_linhas[linha]" },
    { "mDataProp": "vendas_facturas_linhas[factura]" },
    { "mDataProp": "vendas_facturas_linhas[mercadoria]" },
    { "mDataProp": "vendas_facturas_linhas[designacao]" },
    { "mDataProp": "vendas_facturas_linhas[quantidade]" },
    { "mDataProp": "mercadorias_unidades_venda[designacao_abrev]" },
    { "mDataProp": "vendas_facturas_linhas[preco_venda]" },
    { "mDataProp": "vendas_facturas_linhas[taxa_desconto_comercial]" },
    { "mDataProp": "vendas_facturas_linhas[tipo_iva_venda]" },
    { "mDataProp": "vendas_facturas_linhas[taxa_iva]" },
    { "mDataProp": "vendas_facturas_linhas[total_iva]" },
    { "mDataProp": "vendas_facturas_linhas[total_bruto]" }
    ],
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    $('td:eq(5)', nRow).html( DECIMALMask('', '-nnn,nnN.nnn', aData["vendas_facturas_linhas[quantidade]"]) );
    $('td:eq(7)', nRow).html( DECIMALMask('', 'nn,nnn,nnN.NNn €', aData["vendas_facturas_linhas[preco_venda]"]) );
    $('td:eq(8)', nRow).html( DECIMALMask('','nnN.nn%', aData["vendas_facturas_linhas[taxa_desconto_comercial]"]) );
    $('td:eq(10)', nRow).html( DECIMALMask('','nN.n%', aData["vendas_facturas_linhas[taxa_iva]"]) );
    $('td:eq(11)', nRow).html( DECIMALMask('','nn,nnn,nnN.NN €', aData["vendas_facturas_linhas[total_iva]"]) );
    $('td:eq(12)', nRow).html( DECIMALMask('','nn,nnn,nnN.NN €', aData["vendas_facturas_linhas[total_bruto]"]) );
    return nRow;
    }
    } );
    [/quote]

    Is this right?
  • allanallan Posts: 63,727Questions: 1Answers: 10,506 Site admin
    Yup that is one possible way of doing it - another is to use fnRender ( http://datatables.net/ref#fnRender ) which will let you process each string as required. http://datatables.net/ref#bUseRendered can also be useful with fnRender to have DataTables use the original value rather than the rendered one for sorting.

    Allan
  • dcd4u2dcd4u2 Posts: 5Questions: 0Answers: 0
    Thank you Allan,

    Your post was very helpfull. I need to use original values for cells, the mask is only to show data, not to use it.
This discussion has been closed.