Raghav
Raghav

Reputation: 3078

jqgrid custom sorting with duplicates

I have a jQgrid column which would show data as in the below example.

  1. 5 of 10
  2. 2 of 2
  3. 5 of 5
  4. 2 of 10.... etc

    I wanna implement a custom sorting which would sort first based on the number before 'of' and then for duplicates it should use the number after the 'of'.

I have implemented the main sort using the following function.

sorttype: function (cellValue, cellObject) {
                        var sortValueArr = cellValue.split(" ");
                        return parseInt(sortValueArr[0]);
                        //return [parseInt(sortValueArr[0]), parseInt(sortValueArr[2])];
                    }

But am stuck up implementing the secondary-sort-for-duplicates. I tried it with the commented line above. But it is not working.

Please help me out.

The output required is

  1. 2 of 2
  2. 2 of 10
  3. 5 of 5
  4. 5 of 10

Thanks in advance.

Upvotes: 0

Views: 321

Answers (1)

Ben Barden
Ben Barden

Reputation: 2111

Well, it's not a pretty answer, but you if you know a hard maximum for the second number, you can run it as a float. For example, if you can be sure that the second number won't get above, say, 1000, you might use the following

sorttype: function (cellValue, cellObject)
{
    var sortValueArr = cellValue.split(" ");
    return (parseFloat(sortValueArr[0]) + parseFloat(sortValueArr[2])/1000);
}

Upvotes: 1

Related Questions