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?
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;
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/ .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.