First time I use DataTables

First time I use DataTables

FPLSFPLS Posts: 5Questions: 1Answers: 0
edited August 13 in Free community support

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

  • FPLSFPLS Posts: 5Questions: 1Answers: 0

    Excuse me.

    javascript libs loaded:

  • colincolin Posts: 12,635Questions: 0Answers: 2,158

    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

  • FPLSFPLS Posts: 5Questions: 1Answers: 0

    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

  • colincolin Posts: 12,635Questions: 0Answers: 2,158
    Answer ✓

    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

  • FPLSFPLS Posts: 5Questions: 1Answers: 0

    Thank you very much.

Sign In or Register to comment.