Sorting columns with Key-Value pairs when edit type is "select"
When a column edit type is "select", the column sort is sorted by id not by text for this column.
Solution:
The most easy way to solve the problem would be usage of
sorttype defined as function. You can create object or array which
makes mapping of select value to the corresponding text and replace
the select value to the text inside of sorttype. In the case the
text returned by sorttype will be used during sorting instead of
the value:
var typeMapping = {
"1":
"ABC",
"2":
"XYZ",
"3":
"IOU"
};
Use set_col_property to set the sorttype
http://phpgrid.com/documentation/set_col_property/
Complete pseudo code:
http://phpgrid.com/documentation/set_col_property/
Complete pseudo code:
<script>
var typeMapping = {
"1":
"ABC",
"2":
"XYZ",
"3":
"IOU"
};
</script>
...
<?php
$dg = new C_DataGrid("select * from employees",
"employeeNumber", "employees");
$dg -> set_col_edittype("jobCode", "select",
":;1:ABC;2:XYZ;3:IOU;", false);
$typMapping =
<<<TYPEMAPPING
function (value) {return
typeMapping[value];}
TYPEMAPPING;
$dg -> set_col_property("jobCode",
array("sorttype"=>$typeMapping));
$dg -> display();
?>