th3penguinwhisperer
th3penguinwhisperer

Reputation: 466

jqGrid sorting some columns while others don't

I'm new to jqGrid and experiencing something strange. The data from the xml is successfully loading in the table. When I sort on a name in a column the rows are sorted correctly. Now in some columns I only have numbers. 0, ... 176000, ... When I click on the table header the order of the lines change back to how they were listed when initially loaded. (so when I freshly load the page and then click sort on these columns, nothing happens).

Note that I'm using loadonce.

It almost looks like sorting on strings works ok, however on numbers fails.

Can someone point me in the right direction? I don't use any custom sorting code nor formatter for this column.

Upvotes: 0

Views: 1135

Answers (4)

Omar Yassin Carcelen
Omar Yassin Carcelen

Reputation: 111

Just add:

sorttype:'number'

This will sort the column as number.

Upvotes: 0

th3penguinwhisperer
th3penguinwhisperer

Reputation: 466

I believe I found the solution. I fiddled around with sortable, sorttype number and sorttype integer however that didn't made the issue go away.

Then I went to my XML and wondered if it might have to do with the CDATA that was around the data and removed it. No luck either.

The example of vineetpeeyuse gave me a clue. It shows that the name and index are identical and that is not the case for these columns in my code. What I am now wondering is what the use is of the index column as it has to be the same as the name column.

I hope this helps other people!

Upvotes: 0

vineetpeeyuse
vineetpeeyuse

Reputation: 61

you should try using sorttype property while defining the columns of the jqgrid and set it as number type. Example

 colModel:[
             {name:'clientCode',index:'clientCode', sorttype:'number'},
             {name:'buildId',index:'buildId',width:'45px', sorttype:'number'},
             {name:'courseId',index:'courseId',width:'55px', sorttype:'number'}, 
             {name:'courseName',index:'courseName',width:'80px'}
]

Upvotes: 0

Mark
Mark

Reputation: 3123

It would be sorting your numbers as string unless you specify otherwise. You can look at the documentation at http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3acolmodel_options and the sorttype property.

Upvotes: 1

Related Questions