Sorting with Number not working
Sorting with Number not working
arunselvaguru
Posts: 4Questions: 0Answers: 0
Hi,
I am using Jquery Datatables for sorting. I have a field called Capacity. While sorting it sorts as string.
Here is my code:
$(document).ready(function () {
$('#grdCentre').dataTable({
"aoColumns": [{ "bSortable": false }, null, null, null, { "sType": "numeric" }, null]
});
$(".dataTables_length").hide();
$(".dataTables_filter").hide();
});
I am using Jquery Datatables for sorting. I have a field called Capacity. While sorting it sorts as string.
Here is my code:
$(document).ready(function () {
$('#grdCentre').dataTable({
"aoColumns": [{ "bSortable": false }, null, null, null, { "sType": "numeric" }, null]
});
$(".dataTables_length").hide();
$(".dataTables_filter").hide();
});
This discussion has been closed.
Replies
Allan
Allan
I have tried the method and still not able to sorting.
Here is my code:
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a, b) {
var x = (a == "-") ? 0 : a.replace(/,/, ".");
var y = (b == "-") ? 0 : b.replace(/,/, ".");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a, b) {
var x = (a == "-") ? 0 : a.replace(/,/, ".");
var y = (b == "-") ? 0 : b.replace(/,/, ".");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#grdCentre').dataTable({
"aoColumns": [
null,
null,
null,
null,
{ "sType": "numeric-comma" },
null
]
});
});
Let me know if I have to do any changes
Allan
Thank you for your input. I have changed the code like this
<%--
--%>
Now its working fine.
Reason:
When I use the TemplateField , it change the value to string with data. So i have changed TemplateField to BoundField and its not coming with data. Finally its working as expected.
Thank you for your feedback.
-ArunS