How to generate a child DataTable by making Ajax call with Hypertext Link (href)
How to generate a child DataTable by making Ajax call with Hypertext Link (href)
CuroDeveloper
Posts: 8Questions: 2Answers: 0
I have successfully generated a jQuery DataTable using the data from the database for my ASP.NET application. Now, I would like to be able to generate a 2nd table with the details information by clicking on a hypertext link of a Product Key. I do not want to use a table within table "Child Row" method. In other words, I would like to select a row from the parent table and a child table is displayed with details information.
How do you make an ajax call?
<script type="text/javascript">
//jQuery DataTable
var dataSet = <%=JsonLoanProductsData %>
$('#dtLoanProductsByLocation').DataTable({
keys: true,
scrollY: 550,
scrollCollapse: true,
lengthMenu: [[50, 75, 100, -1], [50, 75, 100, "All"]],
data: dataSet,
columnDefs: [
{ "width": "15%", "targets": [0] },
{ "width": "20%", "targets": [2,3] }
],
columns: [
{
"className": 'dt-center',
"data": "LoanProductKey"
},
{ "data": "ProductName" },
{ "data": "ProductTypeEnum" },
{ "data": "LoanTypeEnum" },
{
"className": 'dt-center',
"data": "ProductType",
"visible": false
},
{
"className": 'dt-center',
"data": "LoanType",
"visible": false
}
]
});
</script>
This discussion has been closed.
Answers
Sounds like you want the functionality discussed in this blog:
https://datatables.net/blog/2016-03-25
Kevin
Kevin,
Thank you for replying. I believe your example is very close to what I want. In my application, after you select a row in the parent table, I make an Ajax call to a web method with the row Product Key. The web method returns a set of data based on the selected key. The retrieved data then will be used to populate the child table.
My issue is that I don't know how to handle the retrieved data and the syntax to treat it as the child's table data source. In other words, how do I populate the child table with the retrieved data?
I am close to having it working but I cannot get around the "Uncaught TypeError: $(...).dataTable is not a function on line 115 of the script below (var configHTML = $(htmlDataTable).dataTable)