preventDefault on 'order.dt' ?
preventDefault on 'order.dt' ?
suppose i have the code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/jq-2.1.4,dt-1.10.9/datatables.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,dt-1.10.9/datatables.js"></script>
<script>
$(function() {
$("#dat").dataTable( )
.on('order.dt',function(ev) {
ev.preventDefault(); //appears to have no effect
return false;
});
});
</script>
</head>
<body>
<table id="dat">
<thead>
<tr>
<th>First Col</th>
<th>Second Col</th>
</tr>
</thead>
<tbody>
<tr>
<td>First Row</td>
<td> 1 </td>
</tr>
<tr>
<td>Second Row</td>
<td> 2 </td>
</tr>
</tbody>
</table>
</body>
</html>
my understanding of JQuery is that by convention ev.preventDefault() or returing false should prevent the predicted action (in this case the ordering of the table) yet as far as i can see this does nothing.
I suppose I am asking 2 things:
1) does either preventDefault or returing false actually do anything?
2) is there a way to prevent the table from ordering so i can overwrite it with what i want the event to do myself?
This question has accepted answers - jump to:
Answers
If the event is cancellable, then yes, that is the case.However, the order event is not cancellable. This is something i will add to the documentation - thanks for pointing out that omission.
If you want to apply your own ordering to the table use
columns.orderable
to disable user ordering on the columns.Allan
Is server side ordering not possible then?
The documentation on ordering options is here
https://datatables.net/reference/option/order
It looks like you can completely disable ordering or disable it by column.
Sure - use server-side processing.
Allan