datatable is not displaying the rows
datatable is not displaying the rows
abhivachan
Posts: 2Questions: 1Answers: 0
Datatable is not displaying any rows. using datatable debugger & Browser developer tools, I checked the ajax request is getting the data in json format without any issues. Here's my code. Please help
CSHTML
`
<div style="margin:0 auto;">
<table id="companies-table" class="table table-striped table-bordered table-hover responsive">
<thead>
<tr>
<td>Id</td>
<td>Name</td>
<td>Address</td>
<td>City</td>
<td>State</td>
<td>Country</td>
<td>ZipCode</td>
<td>Phone</td>
<td>Email</td>
<td>Status</td>
</tr>
</thead>
<tbody></tbody>
<tfoot>
</tfoot>
</table>
</div>
`
JavaScript
`
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.3/js/dataTables.fixedHeader.min.js"></script>
<script>
$(document).ready(function () {
var table = $('#companies-table').DataTable({
processing: true,
serverSide: false,
fixedHeader: true,
"ajax": {
"url": "/Company/GetAllCompanies"
},
columns: [
{ 'data': 'CompanyId' },
{ 'data': 'CompanyName' },
{ 'data': 'Address' },
{ 'data': 'CityName' },
{ 'data': 'StateName' },
{ 'data': 'CountryName' },
{ 'data': 'ZipCode' },
{ 'data': 'Phone' },
{ 'data': 'Email' },
{'data': 'Status'}
]
});
});
</script>
`
Ajax Output Based on Datatable Debugger & Browser Developer Toolbar
`
[{"CompanyId":1,"CompanyName":"Unsipegicator Direct Company","Address":"HRGM1S45G9L67Z121","CountryName":"Mozambique","CityName":"Kingston upon Hull","StateName":"Colorado","ZipCode":"10369","Email":"roilood.fsxh@hsztqt.org","Phone":"297-4192231","Fax":"925067-5684","Status":true},{"CompanyId":2,"CompanyName":"Klieraquover Holdings ","Address":"M9V74RCKV0ZQC","CountryName":"Dominica","CityName":"London","StateName":"Oregon","ZipCode":"62786","Email":"gplf196@cwjhcsppm.neqtxx.com","Phone":"190236-1407","Fax":"739-913-2879","Status":false}]
`
This discussion has been closed.
Answers
It is working fine. I fixed it myself
If you are returning a plain array of data, you need to use
ajax.dataSrc
set to be an empty string.Allan