I want to load the following JSON object into Datatables.net but it does not work. I tried to find a solution like this: Datatables.net json data load, but without success.
I use SignalR to pass the JSON from the server-side to the client, and it runs because I can receive the JSON but I can't load it into a Datatable.
Please, could someone help me?
Thanks in advance!
C# code:
cmm_dbEntities db = new cmm_dbEntities();
var result = from a in db.TAB_PN
join b in db.TAB_APPL on a.idapplicability equals b.idapplicability
join c in db.TAB_ISSUE on a.idissue equals c.idissue
select new
{
a.pn,
a.title,
b.appl_desc,
c.issue,
c.issue_date,
c.rev,
c.rev_date,
a.equipment,
a.formattype
};
var obj = new { data = result };
string json = JsonConvert.SerializeObject(obj);
return json;
Here is my JSON:
{
"data": [{
"pn": "346B0300A3300.801",
"title": "Test Bench Replenish Unit, Engine Oil - Operation and Maintenance Manual with Illustrated Parts Breakdown",
"appl_desc": "DESCRIZIONE 005",
"issue": "ISSUE-003",
"issue_date": "2015-03-01T00:00:00",
"rev": "0003",
"rev_date": "AAAAAAAAB9M=",
"equipment": "Test Bench, Replenish Unit, Engine Oil",
"formattype": "XML"
}, {
"pn": "346B0300A3300.805",
"title": "Test Bench Replenish Unit, Engine Oil - Operation and Maintenance Manual with Illustrated Parts Breakdown",
"appl_desc": "DESCRIZIONE 015",
"issue": "ISSUE-004",
"issue_date": "2015-04-01T00:00:00",
"rev": "004",
"rev_date": "AAAAAAAAB9Q=",
"equipment": "Test Bench, Replenish Unit, Engine Oil",
"formattype": "XML"
}, {
"pn": "415808",
"title": "Operating and Maintenance Manual for Ni-Cd Aircraft batteries",
"appl_desc": "DESCRIZIONE 015",
"issue": "ISSUE-001",
"issue_date": "2015-01-01T00:00:00",
"rev": "0001",
"rev_date": "AAAAAAAAB9E=",
"equipment": "Battery",
"formattype": "XML"
}, {
"pn": "415818",
"title": "Operating and Maintenance Manual for Ni-Cd Aircraft batteries",
"appl_desc": "DESCRIZIONE 009",
"issue": "ISSUE-002",
"issue_date": "2015-02-01T00:00:00",
"rev": "0002",
"rev_date": "AAAAAAAAB9I=",
"equipment": "Battery",
"formattype": "XML"
}]
}
Here is my js:
hub.client.inizializzaFiltri = function (data) {
console.log(data);
$('#PNTable').DataTable({
dataSrc: "objects",
columns: [
{ data: null, defaultContent: '' },
{ data: 'pn' },
{ data: 'title' },
{ data: 'appl_desc' },
{ data: 'issue' },
{ data: 'issue_date' },
{ data: 'rev' },
{ data: 'rev_date' },
{ data: 'equipment' },
{ data: 'formattype' }],
order: [[1, "asc"]],
columnDefs: [
{
orderable: false,
className: 'select-checkbox',
targets: 0
},
],
retrieve: true,
select: {
style: 'os',
selector: 'td:first-child'
}
});
}
My HTML code:
<table id="PNTable" class="display">
<thead>
<tr>
<th></th>
<th>pn</th>
<th>title</th>
<th>appl_desc</th>
<th>issue</th>
<th>issue_date</th>
<th>rev</th>
<th>rev_date</th>
<th>equipment</th>
<th>formattype</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>pn</th>
<th>title</th>
<th>appl_desc</th>
<th>issue</th>
<th>issue_date</th>
<th>rev</th>
<th>rev_date</th>
<th>equipment</th>
<th>formattype</th>
</tr>
</tfoot>
</table>