how to change the value of the row if the trans_type==Penalty i want to display the credit column
how to change the value of the row if the trans_type==Penalty i want to display the credit column

$(document).ready(function(){
$("#transactionTable").DataTable();
function fill_dataTable(cancelled=''){
var transactionTable = $("#transactionTable").DataTable({
processing: true,
serverSide: true,
ajax:{
url:'/salesinvoice/transaction/'+'{{$invoice->id}}',
data:{cancelled : cancelled}
},
columns:[
{data:'trans_code', name:'trans_code'},
{data:'trans_date', name:'trans_date'},
{data:'or_no', name:'or_no'},
{data:'or_date', name:'or_date'},
{data:'trans_type', name:'trans_type'},
{data:'debit', name:'debit'},
{
data: 'action',
render: function ( data, type, row){
if(row.trans_type == 'Penalty'){
{data:'credit', name:'credit'},
}
else {
{data:'debit', name:'debit'},
}
var concat_data = '';
if(row.cancelled=='1'){
$('#transactionTable tr:eq(0) th:eq(6)').text("Remarks");
concat_data += ''+row.remarks+'';
}
else{
$('#transactionTable tr:eq(0) th:eq(6)').text("Action");
concat_data += '<div class="btn-group"> <form action="/updatesalesinvoice/transaction/'+row.id+'/'+row.invoice_id+'" method="POST">@csrf';
concat_data += '<button type="submit" class="btn btn-primary" title="Accept transaction"><i class="fa fa-check"></i></button>';
concat_data += '</form> <a href="/salesinvoice/transaction/'+row.id+'/edit" class="btn btn-success" title="Edit transaction"><i class="fa fa-edit"></i></a>';
concat_data += '<a href="#" class="btn btn-primary" title="Cancel invoice" data-toggle="modal" data-target="#addRemarks" data-id="'+row.id+'">';
concat_data += '<i class="fa fa-ban"></i></a></form></div>';
}
return concat_data;
}
}
]
});
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
what I want is:
when the data:"trans_type" has on value: "Penalty" is showing the column Credit
otherwise it is showing the Debit
i add another render function but it returns a data [object Object]
Heres my updated codes returning [object Object] in the row
$(document).ready(function(){
You are returning
return {data:'debit', name:'debit'};
. This will display[object Object]
. You need to return a string or HTML formatted output. Maybe you want something like this:Kevin
it helps bro thanks but i did like this
if(row.trans_type=='Penalty'){
return ''+row.credit+'';
} else{
return ''+row.debit+'';
}
one more thing that debit and credit is number how to format that data into number to show comma separators
where should i insert $.fn.dataTable.render.number(',','.',2) to format the data
i did like this but its giving me error DataTables warning: table id=transactionTable - Requested unknown parameter 'amount' for row 0, column 5. For more information about this error, please see http://datatables.net/tn/4
because my columns in database are debit and credit not amount, if i change the amount to debit only the debit data will show and the credit display 0.00
{data:'amount',
render: function(data, type,row){
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin