我正在使用jqGrid
。其中一列具有可能的值:
Poor, Fair, Good, Very Good, Excellent, Ideal
但是当您按此列排序时,它们按字母顺序排序:
Excellent, Fair, Good, Ideal, Poor, Very Good
而不是您期望的直观顺序。
有没有办法纠正这个?
以下是用于生成网格的PHP代码片段:
$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;
答案 0 :(得分:2)
我如何从您询问有关本地数据排序的上下文中理解。
您可以使用以下colModel选项组合轻松实现您的要求:
edittype:'select', formatter:'select', sorttype:'int'
您可以在此处看到http://www.ok-soft-gmbh.com/jqGrid/CustomLocalSort6.htm的工作示例。 (请不要查看包含的数据。我只修改了另一个示例来获取数据)
实现自定义本地排序的另一种方法是使用sorttype
作为函数或index
作为列模型中的函数。这些功能从3.8版开始存在。有关详细信息,请参阅三角形论坛http://www.trirand.com/blog/?page_id=393/help/custom-local-sort-with-respect-of-the-function-as-index/中的帖子。