Trying to populate datatable using javascript sourced data
Trying to populate datatable using javascript sourced data
Davidsons
Posts: 2Questions: 1Answers: 0
<table class="table" display="hidden" id="datatable"> </table>
@section scripts{
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.22/af-2.3.5/datatables.min.css" />
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.22/af-2.3.5/datatables.min.js"></script>
<script>
var m='@Html.Raw(Json.Encode(Model))';
$(document).ready(function () {
$("#datatable").DataTable({
});
})
</script>
}
**:
** error : Cannot read property 'aDataSort' of undefined TypeError**:
I am trying to populate datatable using javascript data. My model is of type List<Object>
The thing is i have tried the same using model type of datatable, have the same error
Can somebody help?
I am using asp.net mvc:
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This discussion has been closed.
Answers
It doesn't look like you are creating a
thead
in your table. You can add one or usecolumns.title
for each column to create it.Kevin
@kthorngren
yes but the thing is its making an error because of the var m=@Html.Raw(Json.Encode(Model)); line, and i dont know why
var m='@Html.Raw(Json.Encode(Model))';
If you put your variable in ' ... ' you define your variable as a a string no ?
Maybe remove your ' ' to begin with ?
var m= @Html.Raw(Json.Encode(Model));