We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Sort column as a integer

$scope.col = [
    { field: "property_type", headerText: "Property Type", width: 80 },
    { field: "days_outstanding", headerText: "Days Outstanding", width: 90,},
    { field: "lease_sale_type", headerText: "", width: 0},
    ];

When sort using days_outstanding it is sorting as a string and not as a integer.
How to specify to sort this particular column as a integer?

1 Reply

SR Sellappandi Ramu Syncfusion Team October 13, 2015 10:16 AM UTC

Hi Dinesh,

Thanks for contacting Syncfusion support.

While perform sorting operation, we are using typeOf property to check type of sorting data and based on that type, we are sorting the data. So you need to convert the data to integer before perform the sort operation.

Please find the code example and sample for workaround solution.

    <script type="text/javascript">

        angular.module('listCtrl', ['ejangular'])

          .controller('PhoneListCtrl', function ($scope, $compile, $filter, $rootScope) {

              $scope.data = [

                                { accessGroupMarking: "Country1", targetDescription: "Iphone 6", targetName: "2064-prod_SYSA", targetNumber: "1", targetType: "z/OS" },

                                { accessGroupMarking: "Country2", targetDescription: "Lenovo SS", targetName: "ADV-160", targetNumber: "111", targetType: "Oracle" },

                                { accessGroupMarking: "Country3", targetDescription: "Andy's Lenovo T60", targetName: "ACM-T60", targetNumber: "12", targetType: "Windows" },

                                { accessGroupMarking: "Country4", targetDescription: "Lenovo T60", targetName: "ACM-", targetNumber: "101", targetType: "Mac" },

                                { accessGroupMarking: "Country5", targetDescription: " Apple T80", targetName: "ACM-T65", targetNumber: "222", targetType: "Linux" }

              ];

              $scope.columns = [

                     { field: "targetType", headerText: "targetType", width: 100 },

                                 { field: "targetNumber", headerText: "targetNumber", width: 100 },

                     { field: "targetName", headerText: "targetName", width: 100 },

                     { field: "targetDescription", headerText: "description", width: 100 }

              ];

          });

        ej.pvt.fnAscending = function (x, y) {

            if (y === null || y === undefined)

                return -1;


            if (parseFloat(x) != NaN)

                return parseFloat(x) - parseFloat(y);


            if (typeof x === "string")

                return x.localeCompare(y);


            if (x === null || x === undefined)

                return 1;


            return x - y;

        }

        ej.pvt.fnDescending = function (x, y) {

            if (y === null || y === undefined)

                return 1;


            if (parseFloat(x) != NaN)

                return parseFloat(y) - parseFloat(x);


            if (typeof x === "string")

                return x.localeCompare(y) * -1;


            if (x === null || x === undefined)

                return -1;


            return y - x;

        }
    </script>


Sample Link: http://jsplayground.syncfusion.com/25gfyioj

Regards,
Sellappandi R

Loader.
Live Chat Icon For mobile
Up arrow icon