How to fix problems with jquery data tables and a list of objects from ASP.net Web API - Digital Tool Factory blog How to fix problems with jquery data tables and a list of objects from ASP.net Web API - Digital Tool Factory blog

How to fix problems with jquery data tables and a list of objects from ASP.net Web API

The main problem is that data tables does not expect a list of objects, instead it wants a differently formatted json object, something like

data: {“Property”: Value}

etc
Instead it’s getting a pure list, like this

[
{“Name”:”Value},
{“Name”:”Value},
{“Name”:”Value},
{“Name”:”Value},
{“Name”:”Value},
]

Solution – list out the values in the columns property of the data table, like this

$(document).ready(function () {
$(‘#example’).dataTable({
“deferRender”: true,
“processing”: true,
“iDisplayLength”: 25,
“ajax”: {
“url”: “https://domain.com/Ajax/v1.1/ListTypes”,
“dataSrc”: “”
},
“columns”: [
{ “data”: “Name” },
{ “data”: “OtherColumn” }
]
});
});

And you’re done!

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.