Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1145
sorting on a column containing formatted numbers e.g currency
posted

What is the recommended approach to sorting columns within igGrid, whose value is numerical but has already been converted into a formatted string value.

We have a Quantity field with values such as 99 and 987,654 and 98, when sorted we are getting

99

987,654

98

We would want the sorting to produce

987,654

99

98

Regards

Aidan

  • 23953
    Offline posted

    Hello Aidan,

    Sorting respects the column data type. If you provide numericals as strings then they will be sorted as strings. If you want the values sorted as numericals then you need to provide them to the igGrid as numericals and format them in the igGrid column formatter.

    Here is an example:

    var data = [{col1: "99", col2: 99}, {col1: "987,654", col2: 987.654}, {col1: "98", col2: 98}];
    $("#grid1").igGrid({
    	columns: [
    		{ headerText: "col1", key: "col1", dataType: "string", width: "100px"},
    		{ headerText: "col2", key: "col2", dataType: "number", width: "200px", formatter: function (val) {return val.toLocaleString("de");}}
    	],
    	dataSource: data,
    	features: [
    		{
    			name: "Sorting"
    		}
    	]
    });
    
    

    Hope this helps,
    Martin Pavlov
    Infragistics, Inc.