Datatables sorting does not work at all and filtering acts weird

Datatables sorting does not work at all and filtering acts weird

fidelfidel Posts: 7Questions: 1Answers: 0
edited November 2016 in Free community support

I got a datatable which is loaded properly on ready and displaying the expected amount of records coming from my database.

Table init is pretty basic:

$(document).ready(function(){
$('#nameOfDataTable').DataTable();
});

It's getting confusing if i do either try to sort by colum or filter.

Case 1: Sorting
Selecting a column for sorting results in the sort-symbol of the related column being activated/updated BUT the data is not sorted at all (same order as before).
No error output in the Javascript console.

Case 2: Filtering
If i do filter using the default search field it might either:
* Show 'No records found' in the first line BUT still display the other records below
OR
* Nothing happens at all

This depends on the search term but i can't really see a clear pattern in the behaviour.

Again - no error output in the javascript console.

I tested this in both Google Chrome and Mozilla Firefox.
Other data-tables in my project do work properly.

I am clueless what might cause this error in this particular table.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,121Questions: 1Answers: 10,397 Site admin
    Answer ✓

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • fidelfidel Posts: 7Questions: 1Answers: 0
    edited November 2016

    Hi Allen,

    first of all, thanks for the response. I was able to solve the issue, which was caused my my own stupidity ;)

    While adding records to the table in a loop i accidentally created a new <tbody> and </tbody> around each new row/record.

    As a result datatables draw all records without issues, but had issues while trying to sort or filter them, as it only realized the first record.

    To boil it down - having several bodys is critical and i was just not realizing that i was doing that by accident.

This discussion has been closed.