1
0
-1

this is my example code

<script>
$(document).ready(function() {
    
    $.ajax({
        url: 'url_api',
        type: 'GET',
        contentType: false,
        processData: false,
        success: function(response) {
            console.log('Success:', response);
            	  FormUtil.getField("nama_bank_debitur_wiraswasta").val(response.customer_name);
            FormUtil.getField("norek_debitur_wiraswasta").val(response.rek);
			
			//(already fine for this in top)            
             


            let monthlyTotals = {};

            // Iterate over transactions to accumulate monthly totals
            response.transactions.forEach(transaction => {
      
                let month = transaction.date.split('/')[1];

                // Initialize totals for the month if not already
                if (!monthlyTotals[month]) {
                    monthlyTotals[month] = { balance_total: 0, debet_total: 0, credit_total: 0 };
                }

                if (transaction.balance) {
                    monthlyTotals[month].balance_total += parseFloat(transaction.balance.replace(/,/g, ''));
                }
                if (transaction.debit) {
                    monthlyTotals[month].debet_total += parseFloat(transaction.debit.replace(/,/g, ''));
                }
                if (transaction.credit) {
                    monthlyTotals[month].credit_total += parseFloat(transaction.credit.replace(/,/g, ''));
                }
            });

            // this is for id column
            let formattedResults = [];
            for (let month in monthlyTotals) {
                formattedResults.push({
                    bulan: month,
                    mutasi_kredit: monthlyTotals[month].balance_total,
                    rata_rata_saldo: monthlyTotals[month].debet_total,
                    saldo_akhir_bulan: monthlyTotals[month].credit_total
                });
            }

           
            let jsonResult = JSON.stringify(formattedResults);
			console.log('json total : ',  jsonResult); 
            // debitur is my id grid ( how i can set my json to grid )
            FormUtil.getField("debitur").val(jsonResult);

        },
        
            error: function (xhr, status, error) {
                console.error('Error:', error);
            }

    });
});
</script>

this is example grid 

and this example value on console log json total

so how i can set jsonResult to my grid with id = "debitur".


and last important. it can more than 2 for json result

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      Hi Galvin, please check Prepopulate a grid with data via Javascript 


      Let us know if this helps.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        if just want to console the json data as grid view, use

        console.log(jsonResult);


          CommentAdd your comment...