First time I use DataTables
First time I use DataTables
This is my first time using DataTables.
I have a simple razor page, with a simple javascript and I am not able to load the data from an api that works and that is tested with postman.
I obtain an error undefined aDataSort: Log file attached.
Libraries:
css:
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
javascript libs:
https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js
Javascript code:
$(function () {
$('#record').dataTable({
"ajax": {
"url": "https://localhost:44330/api/record/4", //this work fine
"type": "GET"
}
});
});
Razor page: as simple as: (editor not allow tags)
table id="record" class="table table-sm"
/table
Thank you very much for your help.
This question has an accepted answers - jump to answer
Answers
Excuse me.
javascript libs loaded:
I load this libraries:
https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js
https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js
I suspect the problem is that you're receiving objects back from the Ajax query, so you'll need to define the columns with
columns
- see example here.If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thank you very much Colin.
First of all, great job with this plug-in. Congratulations !!
I also want to apologize for phrasing the question so badly. I wrote it at 3am and I was already tired.
Yes, defining the columns has been part of the problem, but I found this tutorial that has solved my question.
https://www.ezzylearning.net/tutorial/how-to-use-jquery-datatables-with-asp-net-core-web-api
Can I find something similar to this tutorial in the manual?
As this is the first time I have used DataTables I was a bit lost. I have already used the bootstrap-table plug-in, but Datatables seems better to me.
Thanks again
Glad all sorted. This thread might've helped, but as you're up and running, I'd say stay with what you've got
Colin
Thank you very much.