Update a specific cell in a table.

Update a specific cell in a table.

classic12classic12 Posts: 228Questions: 60Answers: 4

Can't find an example anywhere.

I have the row index of tableInvoices

$('#dtInvoices').on( 'select.dt', function ( e, dt, type, indexes ) {
      selectedInvoiceID = tableInvoices.cell('.selected', 0).data();  
        if (currentInvoiceID !== selectedInvoiceID )
            {
                selectedInvoiceIndex = table.row( this ).index() ;

            }
      } );

Elsewhere I calculate some totals and need to post these into dtInvoices

I see

editorInvoices.set( 'invoice.totalNett', (total));

What is the syntax to update ( column 'invoice.totalNett' row selectedInvoiceIndex )

Cheers

Steve Warby

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    You need to trigger editing on that row first. You can do inline editing with inline() or you can trigger editing on the whole row with edit() and pass in the row index.

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4
    edited December 2017

    Hi Allan,

    I need to trigger this on another table on a dependent action.

    I select the index here

    $('#dtInvoices').on( 'select.dt', function ( e, dt, type, indexes ) {
          selectedInvoiceID = tableInvoices.cell('.selected', 0).data(); 
            if (currentInvoiceID !== selectedInvoiceID )
                {
                    selectedInvoiceIndex = table.row( this ).index() ;
     
                }
          } );
    

    When editing the dtInvoiceDetails table I am using

           
           editorInvoiceDetails.dependent( ['inv_list.quantity','inv_list.sellPrice'], function ( val, data ) {
           //event: 'keyup change'
           // need to update all the row total etc and the invoice details
           var quant = Number(editorInvoiceDetails.field( 'inv_list.quantity' ).val());
           var sell = Number(editorInvoiceDetails.field( 'inv_list.sellPrice' ).val());
           var total = quant * sell ;
           var vatRate = Number(editorInvoiceDetails.field( 'inv_list.vatRate' ).val());
           var lineTotal = total* (vatRate/100) ;
           lineTotal = lineTotal + total;
           //console.log('total is ' + total);
           editorInvoiceDetails.set( 'inv_list.lineTotalNett', (total));
           editorInvoiceDetails.set( 'inv_list.lineTotal', (lineTotal));
           var invNett = tableInvoiceDetails.column( 8 ).data().sum(); 
           invNett = invNett.toFixed(2);  
           console.log(' invNett = '+invNett);
           var invTotal = tableInvoiceDetails.column( 9 ).data().sum(); 
           invTotal = invTotal.toFixed(2);  
            console.log(' invTotal = '+invTotal);
            var invTax;  // sum of line total - invNett
            invTax = invTotal - invNett;
    // now set the values in the tableInvoices nett - VAt - total
            //editorInvoices.set( 'invoice.invNett', (invNett));
            //editorInvoices.set( 'invoice.invTax', (invTax-invNett));
            //editorInvoices.set( 'invoice.invTotal', (invTax));
            //alert( 'Call Data index: '+tableInvoices.row( this ).index() );
            //selectedInvoiceIndex
           console.log('Invoice totals are '+ invNett + ' ' + invTotal + ' ' +  invTax);
    } , {event: 'keydown'});   
    

    So I need to update dtInvoices selectedInvoiceIndex with invNett - invTotal & invTax

    I see in the docs

    table.cell( 0, 0 ).data( 'Updated' ).draw();.
    

    But how do I specify the row to update ?

    Cheers

    Steve Warby

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Sorry,

    brain freeze and late nights

       console.log('Invoice total are '+ invNett + ' ' + invTotal + ' ' +  invTax);
       tableInvoiceDetails.cell( currentSelectedInvoiceIndex, 5 ).data( invNett ).draw();
       tableInvoiceDetails.cell( currentSelectedInvoiceIndex, 6 ).data( invTax ).draw();
       tableInvoiceDetails.cell( currentSelectedInvoiceIndex, 7 ).data( invTotal ).draw();
    
This discussion has been closed.