I'm trying to populate a table when a user clicks another table's row. I have an onClick event in the <tr> tag of the first table which fires a function to send three properties to my webapi. I have a named handler which takes the three properties and uses them as input values to another method to retrieve data from Azure Tables. The response is pre-formatted JSON data which I feed to the JavaScript code.
What I'm seeing in my rendered view is a long string of JSON text; no columns or rows at all. According to the documentation I should be able to bind the dataSet to the data value of the DataTable and build the table dynamically.
JavaScript:
function GetActivityLog(pk, rk, cn) {
var dataSet = $('#tblActivityLogs').load('/Nodes?handler=ActivityLog' + '&PartitionKey=' + pk + '&RowKey=' + rk + '&ComputerName=' + cn);
$('#tblActivityLogs').DataTable({
"ajax": {
url: '/Nodes?handler=ActivityLog' + '&PartitionKey=' + pk + '&RowKey=' + rk + '&ComputerName=' + cn,
data: dataSet
}
});
console.dir(dataSet);
}
$(document).ready(function () {
$('#tblActivityLogs').DataTable({
"order": [[0, "desc"]],
columnDefs: [
{
targets: 0,
className: 'dt-body-nowrap'
}
]
});
})
Razor/HTML:
<tr onmouseover="" style="cursor: pointer;" role="button" id="getActivtiy" onclick="GetActivityLog('@item.PartitionKey','@item.RowKey','@item.ComputerName');">
HTML Table:
<div class="row">
<div class="col-lg-12">
<table id="tblActivityLogs" class="display"></table>
</div>
</div>
C# code:
public async Task<ContentResult> OnGetActivityLog([FromQuery] string PartitionKey, string RowKey, string ComputerName)
{
Activities = await _azureTableConnection.GetActivitiesAsync(PartitionKey, RowKey, ComputerName);
return Content(JsonConvert.SerializeObject(new { Activities }));
}
console.dir(dataSet) output:
UPDATE:
Set a breakpoint before the ajax call to test the function and input values but still get an (undefined) error.

console.dir(dataSet)in yourGetActivityLogfunction and add the output to your question?dataSetappears to be a table object itself and not the raw JSON I would have thought. Maybe I shouldn't be doing a$('#tblActivityLogs').load?