views:

29

answers:

1

I am using jqGrid. One of the columns has the possible values:

Poor, Fair, Good, Very Good, Excellent, Ideal

But when you sort by this column they are ordered alphabetically like:

Excellent, Fair, Good, Ideal, Poor, Very Good

Instead of the intuitive order you would expect.

Is there a way to correct this?

update

Here is a snippet of the php code for generating the grid:

$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$conn->query("SET NAMES utf8");
$grid = new jqGridRender($conn);


//Class to generate query
require('DiamondSQL.php');
$dsql = new DiamondSQL();

$dsql->diamond_table = "rapnet_diamonds";
$dsql->shape_column = "shape";
$dsql->carat_column = "carat";
$dsql->clarity_column = "clarity";

$dsql->setShapes($_GET['shapes']);
$dsql->setCaratMin($_GET['caratMin'] ? $_GET['caratMin'] : "0");
$dsql->setCaratMax($_GET['caratMax'] ? $_GET['caratMax'] : "5");
$dsql->setClarityMin($_GET['clarityMin'] ? $_GET['clarityMin'] : "FL");
$dsql->setClarityMax($_GET['clarityMax'] ? $_GET['clarityMax'] : "I3");

$qry = $dsql->buildQuery();

$grid->SelectCommand = $qry;
$grid->dataType = 'json';
$grid->setColModel();
$grid->setUrl('myfirstgrid.php');


$grid->setGridOptions(array(
    "caption"=>"Diamonds Found",
    "rowNum"=>200,
    "sortname"=>"diamond_id",
    "hoverrows"=>true,
    "sortable"=>0,
    "scroll"=>1,
    "height"=>300,
    "altRows"=>true,
    "colNames"=> array('ID', 'Shape', 'Carat', 'Clarity', 'Color', 'Cut')
));

$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
A: 

How I understand from the context you ask about local data sorting.

Your requirements you can very easy implement using combination of following colModel options:

edittype:'select', formatter:'select', sorttype:'int'

A working example you can see here http://www.ok-soft-gmbh.com/jqGrid/CustomLocalSort6.htm. (Please, don't look at the data contain. I just modified another example to have your data)

Another way to implement custom local sorting is usage of sorttype as function or index as function in the column model. These features exist starting with version 3.8. For details see my post in the trirand forum http://www.trirand.com/blog/?page_id=393/help/custom-local-sort-with-respect-of-the-function-as-index/.

Oleg
Thank you for showing me an example, however I am loading it as json from the server via php. I just didnt realize it was reloaded from the server when sorted. Please see my updates that shows the php code for generating the grid.
John Isaacks
I don't use PHP for software development, so I can't get you direct advice. But somewhere you should define a SQL statement (see http://ponidi.wordpress.com/2009/11/17/tutorial-jqgrid-1-intro/) with **ORDER BY** part. Inside of `ORDER BY` part you should not use just `$sidx $sord` but make for example an addition JOIN to a table which has two columns: the names like "Poor", "Fair", "Good" and so on and an integer value like ID or Weight, so that sorting by this ID or Weight instead of names "Poor", "Fair" etc will gives you correct sort order.
Oleg