Is there a function I can use to see the error?

Is there a function I can use to see the error?

orionaseliteorionaselite Posts: 49Questions: 13Answers: 4
edited August 2017 in Free community support

Assume I am trying to update a few fields without user interaction like this

table.column( 1 ).data().each( function ( value, index ) {
        var current_row_data1 = $('#portfolio').dataTable().fnGetData( index );
        var amount_of_coins1 = parseFloat(current_row_data1.amount_of_coins).toPrecision(15); 
        var row_coin_value1 = parseFloat(current_row_data1.current_coin_value).toPrecision(15);
        //console.log("api result id = "+result[0].id);
        //console.log("api result usd_price = "+result[0].price_usd);
        //console.log("amount of coins for row"+index+" = "+amount_of_coins);
        var cash1 = row_coin_value1 * amount_of_coins1;
        cash1 = cash1.toPrecision(15);
        console.log("amount of coins = " + amount_of_coins1);
        console.log("coin value = " + row_coin_value1);
        console.log("current cash = " + cash1);
        editor.edit( index,false ).set({current_coin_value:row_coin_value1,current_cash:cash1}).submit();
        }); //end .each

My console.log commands show me the correct values and I assume

editor.edit( index,false ).set({current_coin_value:row_coin_value1,current_cash:cash1}).submit(); //should update the rows without user interaction with my specified values / calculation for each index right? I am at a case where the update doesn't occur in my db. I was wondering if I could somehow log the possible reason for the failure of the line

        editor.edit( index,false ).set({current_coin_value:row_coin_value1,current_cash:cash1}).submit();

Answers

  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin

    The problem is that the Editor submission is async, but the each() function being executed is synchronous. As such, before Editor has been able to finish submitting the previous edit it is already being instructed to submit a different one.

    Rather than submitting each row initially, I would suggest you use Editor's multi-row editing feature. That way the data can be submitted to the server in a single Ajax request. You can use the Editor API to set the individual values.

    Regards,
    Allan

This discussion has been closed.