Beginner's question
Beginner's question
Hey folks,
Before we start, let's get out of the way that I have literally zero Javascript experience, so I'm sure the question I'm about to ask is pretty fundamental.
I'd like to make my columns sortable with null values on the bottom, regardless of whether it's sorted ascending or descending. I'm trying to use the solution found here. However, I have literally no idea what I'm doing.
Here's my code. When sorting by Core Word Count, the row for Fortuna Fortibus Favet should always appear last regardless of sorting direction. What have I done wrong? (Feel free to point out things that I have done wrong unrelated to my question!)
Thanks in advance...
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script src="//cdn.datatables.net/plug-ins/1.10.21/sorting/absolute.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.js"></script>
<script>
var wordcount = $.fn.dataTable.absoluteOrderNumber(
{ value: '', position: 'bottom' } );
$('#table_id').DataTable( {
columnDefs:
{
targets: 2,
type: wordcount
}
} );
</script>
<script>
$(document).ready( function () {
$('#table_id').DataTable({"paging": false}
);
} );
</script>
<table id="table_id" class="display">
<thead>
<tr>
<th>Author</th>
<th>Title</th>
<th>Core Word Ct.</th>
</tr>
</thead>
<tbody>
<tr>
<td>Arnold</td>
<td>Cloelia: Puella Romana</td>
<td>166</td>
</tr>
<tr>
<td>Ash</td>
<td>Camilla</td>
<td>207</td>
</tr>
<tr>
<td>Belzer & Pelegrin</td>
<td>Fortuna Fortibus Favet</td>
<td></td>
</tr>
</tbody>
</table>
</head>
<body>
</body>
</html>
This question has an accepted answers - jump to answer
Answers
Check your browser's console for errors.
Thanks for the reply. I didn't even know about the console...
After resolving some syntax errors, it's telling me:
"Uncaught TypeError: $.fn.dataTable.absoluteOrderNumber is not a function"
I suppose I made some mistake in loading the files? How do I fix this?
Your code shows two sets of < script >< /script > tags.
Put the contents of the first script into the second script, after your DT initialisation code
$('#table_id').DataTable({"paging": false} );
Then get rid of the first script.
Not sure if that's all you need though - I haven't used that sorting plug-in.
Thanks. I tried that, and I get the same error as above, plus this one:
This is the code now:
Load your DT script before your plug-in script.
ALSO - missed this at first - you have two of these:
where you only want one.
Your columnDefs should follow your "paging": false.
Thanks for your patience with me on this. No more console errors, so that's progress! But it's still not sorting right...
Here's what I have now:
I figured it out! Just needed some square brackets:
Thank you so much for your help!`
You're welcome.