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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sort column as a integer

Thread ID:

Created:

Updated:

Platform:

Replies:

120758 Oct 12,2015 02:01 PM UTC Oct 13,2015 10:16 AM UTC JavaScript 1
loading
Tags: ejGrid
Dinesh Theetla
Asked On October 12, 2015 02:01 PM UTC

$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?

Sellappandi Ramu [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;