7

I've noticed when I sort a column with numeric values it does not seem to sort correctly. For example I have a column with the following numbers: 565, 5786, 6335, 6351, 61447. When I sort the column (DESC) the numbers are ordered as follows:

  • 6351
  • 6335
  • 61447
  • 5786
  • 565

The problem seems to be in sorting numbers vs. text.

For reference I am using "angular-ui-grid": "~3.1.1"

2
  • the numbers are sorted as String and not as numbers. look at the example: ui-grid.info/docs/#/tutorial/103_filtering Commented Apr 13, 2016 at 8:20
  • @thegio Thanks :) Yes the problem was due to the datatype of the column. Commented Apr 13, 2016 at 10:57

2 Answers 2

10

Try giving column type as "number" for this. The sort algorithm is chosen based on the column type. ui-grid will guess the type based on the data, although if you load data asynchronously after the columns it will often decide all your columns are string. You can explicitly set the column type in the column def using type:'number'.

More details here

Sign up to request clarification or add additional context in comments.

2 Comments

I had mentioned the type in columnDef using type='number'. But somehow it was not picking up. I had to explicitly set the column type to 'number' for that particular field and now it works. Thanks a lot for your help :)
You are wc! In column defs you had to use type:"number", colon instead of equals..
2

Just add a type: 'number' to the column definition -columnDefs- in your js file. it will work well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.