I have a DataTables.js table with a column that has numeric values with decimal points. Currently, it’s being ordered like "1", "1.1", "10", "2"
, but I would like to order it as "1", "1.1", "2", "10"
. Strangely enough, if I click the ordering arrow after the page has loaded, it does order it the way I want. Anyway, according to their documentation, something like this should work:
//Custom ordering function
DataTable.ext.type.order['numeric-decimal-pre'] = function (data) {
return parseFloat(data) || 0;
};
//Initialize datatable
let table = new DataTable("#@(Model.Id)", {
columnDefs: [
{
type: "numeric-decimal",
targets: 0,
},
],
order: [[0, "asc"]],
});
However, while no errors are popping up in the console, it’s also not changing the ordering in any way.