Overwritten columns

Overwritten columns

giulichajarigiulichajari Posts: 19Questions: 8Answers: 0

I have a bill form. And i need to create calculated fields. I achieved it but all the records save the same value, the value of the last inserted.
I am working with a session:

       if (data!==null){

       keys = Object.keys(data);
         $.each(keys, function (i, item) {
      details = data[item];
        q[q.length] = { "nombre": item, "details": details };
       });

         c = { data: q };}


         t=  $('#factura').DataTable({

           data:q,
            columnDefs: [
            { type: "num", symbols:"$" , targets: 3 }
          ],

        columns: [
        {data:"details.cantidad", title: "CANT" },
        {"data": "details.nombre", title: "NOMBRE" },
       {"title": "P/U" , "data": "details.precio"},     
         {title: "SUBTOTAL",

          render: function(data, type, row, meta) {
            return details['precio'] * details['cantidad'];
        }
       },
        {title: "Alicuota",


        render: function(data, type, row, meta) {
            return details['alicuota'];
        }
         },
          {title: "Alicuota",


        render: function(data, type, row, meta) {
            return (details['precio'] * details['cantidad'])*(parseFloat(details['alicuota']) /100);
        }
         },
       {  title:"ACCION",

            className: "center",
            defaultContent:"<input type='radio' class='e' name='seleccionado'/>",

        }
            ], 

i was trying it here http://live.datatables.net/joyafeyo/1/edit, but the datatable is not shown.

As you see i am working with a session object. But i don't know how to access it in the render function to make calcs.
In the singles fields it works properly. The SUBTOTAL and Alicuota field also make the calc but the value of the lat inserted records is overwritten in all the records.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @giulichajari ,

    You could either have an ID for that row that isn't shown, something like this example here, or you could add the information into a column that isn't shown, and reference that in the render function,

    Cheers,

    Colin

  • giulichajarigiulichajari Posts: 19Questions: 8Answers: 0

    Well,of course i have the id in the session, i do this:
    {data:"details.id"},
    {
    "targets": [0],
    "visible": false
    }
    Now, how do i refer to this?

  • giulichajarigiulichajari Posts: 19Questions: 8Answers: 0

    Hi @colin finally the hidden id was not necesary, i do that:

          {title: "SUBTOTAL",
           "render": function ( data, type, full, meta ) {
            var t=$("#factura").DataTable();
           var row=t.row(meta.row).data().details;
           var sub=row.precio * row.cantidad
          return "$"+sub.toFixed(2) ;
       } },
    
This discussion has been closed.