datagrid sort column by substring(string) first, then by another substring(number)

3512
0
03-12-2015 07:53 PM
WuYang
by
New Contributor II

In my widget, I have a datgrid which get data from sql server. One of the column is string. The values in this column include 2 parts:

(1) the first part is a string

(2) the last part is a number

The following is sample data:

JP2001/12-1

JP2001/12-12

JP2001/12-13

JP2001/12-15

JP2001/12-19

JP2001/12-2

JP2001/12-3

JP2001/12-4

JP2001/12-6

JP2001/15-1

JP2001/15-11

JP2001/15-14

JP2001/15-6

JP2001/15-9

The first part like "JP2001/12-", whereas the last part is the number 1,2,3,4,...11,12...

In order to sort this column, in my sortCompareFunction, I need to compare the first part at first, if the first part

value is the same, then compare the last part number value. 

The desired sorting result should be:

JP2001/12-1

JP2001/12-2

JP2001/12-3

JP2001/12-4

JP2001/12-6

JP2001/12-12

JP2001/12-13

JP2001/12-15

JP2001/12-19

JP2001/15-1

JP2001/15-6

JP2001/15-9

JP2001/15-11

JP2001/15-14

But I failed to find a way to make it work. Any ideas? Thanks.

Tags (3)
0 Kudos
0 Replies