I have a student records in datatable if I click on any single record it performs two operations.
Get Student detailed Information and it is working fine as mentioned in the image circled in green using getJson.
I also want to get all invoices of selected student and its payments.
NOTE: Invoices can be one or more and payment also can one or more.
Issue - Circled in Red
a. I am getting No data available in table first row of datatable.
b. Only getting data from Invoice table and not getting data from payment table.
c. Not able to select record from table.
Solution / Workaround Looking for
As user select any student from list it should show all invoice and its corresponding payments then move on to next invoice and its related payments.
Example:
Student ID : 123
Invoice ID : 12345, 12347, 123479
Payments ID : 12 for invoice id 12345, 14 for 12345, 17 for 12347 and so on.
JSON CODE:
var oTable1;
oTable1 = $('#invoiceNo').dataTable();
$('#invoiceNo').on('click', 'tr', function ()
{
var stu_id = $(this).find('td').eq(0).text();
var aid = parseInt(stu_id);
//alert(aid);
$.getJSON("/Transaction/showStu_Inv_Pay",
{
id: aid
},
function (data) {
num_rows = data.length;
alert(num_rows);
var myTable = $('#inv_pay').DataTable();
myTable.clear().rows.add(myTable.data).draw();
$(data).each(function (index, item) {
$('#inv_pay tbody').append(
'<tr><td>' + this.InvoiceID +
'</td><td>' + this.InvoiceIDate +
'</td><td>' + this.Invoice_Type_Name +
'</td></tr>'
)
});
});
});
Linq Query
public IList<Transaction> GetInvByStuID()
{
try
{
DBAPPSEntities _db = new DBAPPSEntities();
this.Invoice_Type_Name = "Invoice";
IList<Transaction> List = (from q in _db.DEL_STU_INV
where q.STU_ID == this.Stu_ID
select new Transaction
{
InvoiceID = q.INVOICE_ID,
InvoiceIDate = q.Inv_Issue_Date,
InvoiceDDate = q.Inv_Due_Date,
Invoice_Month1 = q.Inv_Month_1,
Invoice_Month2 = q.Inv_Month_2,
Invoice_Month3 = q.Inv_Month_3,
Invoice_Note = q.Inv_Note,
Invoice_Adjustment = q.Adjust_Type,
Invoice_Type_Name = this.Invoice_Type_Name,
}).ToList();
return List;
}
catch
{
return null;
}
}
NOTE:- The linq query is only from invoice table and not sure how to combine with payment table and it can be altered.
Section-101
Controller - Setting Student ID
public JsonResult showStu_Inv_Pay(int id)
{
var model = new Transaction { Stu_ID = id }; // student id set to model
var data = model.GetInvByStuID();
return Json(data, JsonRequestBehavior.AllowGet);
}
Section 102
Sample Data
Section 103 - Update - 1
Section 104 - Update - 2




