Установите пустые точки данных для использования максимального значения
function sortEventsByOrder(a, b) {
const startA = parseInt($(a).data('order')) || Number.MAX_VALUE;
const startB = parseInt($(b).data('order')) || Number.MAX_VALUE;
return startA === startB ? 0 : startA > startB ? 1 : -1;
}
$('#eventList').append($('#eventList li').sort(sortEventsByOrder))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="eventList">
<li data-order="5"> Element 5
</li>
<li data-order=""> Element 3
</li>
<li data-order="6"> Element 6
</li>
<li data-order="1"> Element 1
</li>
<li data-order="2"> Element 2
</li>
<li data-order="4"> Element 4
</li>
</ul>
числа с десятичными знаками
function sortEventsByOrder(a, b) {
var orderA = $(a).data('order')
var orderB = $(b).data('order')
const startA = orderA === "" ? Number.MAX_VALUE: +orderA;
const startB = orderB === "" ? Number.MAX_VALUE: +orderB;
return startA === startB ? 0 : startA > startB ? 1 : -1;
}
$('#eventList').append($('#eventList li').sort(sortEventsByOrder))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="eventList">
<li data-order="5"> Element 5
</li>
<li data-order=""> Element 3
</li>
<li data-order="6"> Element 6
</li>
<li data-order="0"> Element 1
</li>
<li data-order="2.2"> Element 2
</li>
<li data-order="2.3"> Element 4
</li>
</ul>