I have a Web API built with ASP.NET MVC. The results of hitting that API look something like this:
{
"RequestID":1,
"Options": [
{"Id":"A", "Name":"Alpha"},
{"Id":"B", "Name":"Bravo"}
],
"Responses":[
{"Id":123, "Name":"Test 1", "Description":"This is the first response"},
{"Id":222, "Name":"Test 2", "Description":"This is the second response"},
{"Id":333, "Name":"Test 3", "Description":"This is the third response"},
]
}
I want to load the response of the Web API into a data table using the DataTables plugin. In an attempt to do this, I have the following:
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
</head>
<body>
<table id="properties" class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th class="sortable">Name</th>
<th>Description</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('#properties').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
'url':'/api/Search?query=Test'
}
});
});
</script>
</body>
I based the implementation off of the example found here. My problem is, it doesn't work. Its like the data table doesn't know to use the Responses property as the data set for the data table. However, I can't figure out how to set that.
Does someone know how I can load the objects in the Responses array into the data table?
Thank you!