As you can see in the screenshot below, the sorting is not working properly.
The Usage column is working because of using file-size
plugin. the Registered Users and Not-Registered is not sorting properly because there is no plugin for numeric with a percentage sorting that's what I think, so I tried the aoColumns
with stype
attr of numeric
but the sorting seems to be worsened.
Code used:
$("#myDatatable").DataTable({
"searching": false,
columnDefs: [{
targets: "datatable-nosort",
orderable: false
}]
});
Expected results should be when I sorted Registered Users is:
Registered Users Not-Registered
13.0(87.0%) 2.0(50.0%)
2.0 (100.0%) 2.0(100%)
Which version of DataTables are you using? DataTables will not sort a column numerically if any of the cells contain non-numeric content, other than "-"; in your example, the parentheses and percent signs cause the sorting to default to "html."
Depending on which version of DataTables you are using, it is possible that adding "num-fmt" as the type or "numeric" as the sType might work around this issue.
For DataTables v1.10:
$('#myDatatable').dataTable({
"columnDefs": [
{ "type": "num-fmt" }
]
});
(see https://datatables.net/reference/option/columns.type#Type )
If you are using DataTables v1.9 or earlier, forcing the type to numeric would be in the following format:
$('#myDatatable').dataTable({
"aoColumnDefs": [
{ "sType": "numeric" }
]
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.