Showing 0 to 0 of 0 entries (filtered from NaN total entries)
Showing 0 to 0 of 0 entries (filtered from NaN total entries)
mpm
Posts: 15Questions: 8Answers: 0
My datatable shows some rows but doesn't show a good format of Date, this is a screenshot :
and this is my Ajax code:
@section scripts {
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#tableconsommation").DataTable({
"ajax": {
"url": "/Consommations/GetList",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "Date_consommation", "name": "Date_consommation" },
{ "data": "Qtité_consommée", "name": "Qtité_consommée" },
{ "data": "Id_unité", "name": "Id_unité" },
{ "data": "Id_consommation", "name": "Id_consommation" },
{ "data": "Unités_de_prod", "name": "Unités_de_prod" },
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"language": {
"processing": "encours....veuillez patienter"
}
});
});
</script>
}
This discussion has been closed.
Answers
Hi mpm,
I suspect the JSON response to the Ajax request is sending the date in that format - DataTables would just display it 'as is'. It's then possible that the slashes are messing up something else internally.
I'd say fix the JSON format first, even post it here if that would help, and hopefully that'll resolve the status summary line.
Cheers,
Colin
Thank you colin for your reply, this is the code in my Controller:
Would you be able to post the JSON that it sends, please? That would be the most useful as we can see what's being passed to DataTables.
I thought that you mean the Controller method, In my project I have this Model:
And the Controller:
And in my View:
Hope that I understand your request, Thanks in advance .
Hi,
No, I was hoping to see the data that gets transferred from the server, back to DataTables - so in this example here, it's what you see in the Ajax tab. You can also get in the browser's Network tab.
Cheers,
Colin
Hi colin, that's what I get when I changed [HttPost] to [HttpGet]:
Thanks for that, and yep, you're sending those backslashes and
Date(number)
back in your request. They don't appear to do any harm, as shown here, but I suspect that's not what you really want to be showing.The problem with the summary status, I think, is because of the JSON response, you're not including the paging information. It should also contain elements like these:
See this example, the format is in Ajax tab.
Thank you colin, how can I fix the format problem of Date,?
There's two ways you can.
change your server-side script to send data in the format you wish to display. This is the best solution, since the server is likely to be nimbler and better suited to that, especially if the dataset is large.
render the column on the client, with
columns.render
- see the functions near the bottom of that page. Here, you can strip out the blackslashes from\/Date(1520377200000)\/
and convert the date. However, while it will work, there may be a performance cost to doing this.Hope that helps,
Cheers,
Colin