hi formatted nunber desc ro asc
hi formatted nunber desc ro asc
Hi I'm creating a table using DataTables. but in one column I have counts as
2016 / 1
2016 / 2
2017 / 1
2017 / 2
2017 / 3
Can not I sort it out properly?
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num": function ( a ) {
a.replace(/[^\d\-\.\/]/g, '');
return parseFloat(a);
},
"formatted-num-asc": function ( a, b ) {
return a - b;
},
"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );
$(document).ready(function() {
$('#ornek').DataTable({
'columdefs' : [
{ type: 'formatted-num', targets: 0 },
{ type: 'formatted-num', targets: 0 },
null,
null,
null,
null
]
});
} );
This question has an accepted answers - jump to answer
Answers
That sorting plug-in would format the data in that column as
20161
,20162
. Its a bit hacky, but that would work up to 9 after the/
. So if they are quarters, it should be fine. If it is months, you'd need to pad it with a0
.If you can link to the page showing the issue, that would be useful.
Allan
hi thanks Allan
my work in here : http://jsfiddle.net/fm8so8na/9/
https://jsfiddle.net/fm8so8na/10/
A few changes I've made:
pad
approach I mentioned above. Note that I usedString.prototype.padStart
, so it will only work in browsers which support that function (Chrome, Edge, Firefox, Safari apparently all do at their latest versions). Replace that if you need it to work with older ones.columnDefs
notcolumndefs
(it is case sensitive).Allan
Hello, thank you very much, allan. you are very good but at the same time I am trying to use it with an asp.net repeater. I have a labels in the repeater. Can you help me? Thank you so much
Not there I'm afraid. The support I can offer doesn't extend to ASP.NET server side. You'd be best asking on StackOverflow or similar for a generic ASP.NET question.
Allan
hello allan. thank you so much. the error was caused by me. In ASP.NET, instead of passing the label to <% # Eval ("Number")%> write. thank you so much