Sorting columns with Key-Value pairs when edit type is "select"

Question:
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:

<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();
?>

Datagrid Edit

  1. Constant value in create/edit form
  2. Display column in grid but hide when edit
  3. inline editing limited to single cell
  4. Get value from a specific cell from selected row
  5. phpGrid insert error - Need to hide primary key during edit
  6. Unable to edit
  7. Use arrow key to navigate a grid
  8. WYSIWYG doesn't work
  9. Editable Datagrid with Add Only Ability
  10. Change edit properties without modifying the source code
  11. Auto Increment (auto-increment) Field validation Due to Underscore Character in Primary Key
  12. CRUD (Create, Remove, Update, Delete) Not Working
  13. Dropdown Concatenation
  14. How to preserve a value of NULL as on update as it is being set to 0
  15. Cannot save or edit records. How to debug?
  16. Show a column as link based on value of another column
  17. Verify uniqueness of a new value entered when edited or added through phpGrid before saving
  18. Soft-delete record by flagging a value (Flag for delete)
  19. Must fill every fields to save, or nothing gets saved!
  20. Displaying TIMESTAMP Fields in an Editable Grid
  21. Datetime Format
  22. Create edit type "select" options manually from SQL query
  23. Access local array data source
  24. How to Obtain Entire Datagrid Data as an Array?
  25. Center Add/Edit Form
  26. Save stored value in PHP Session when inserting
  27. Save Local Data Array Back to Server via Ajax
  28. How to set the "select" col_edittype be readonly?
  29. Dynamic dropdown based on cell value in a row.
  30. How to Increase Size of Multiple Select in Edit Form
  31. Save Data in Calculated/Virtual Column to Database
  32. Sorting columns with Key-Value pairs when edit type is "select"
  33. Sorting columns with Key-Value pairs when edit type is "select"
  34. Week start on Monday
  35. How to grab the table rows in a grid
  36. How to view Sql generated during CRUD?
  37. How to show remaining characters in a field on the edit form?
  38. Use Inner Join
  39. Custom button in action column
  40. Edit Grid of a JOIN or a complex query
  41. How do I make lookup fields (id fields referencing to other table) make dropdown from other table?
  42. Capture time stamp on submit
  43. Sample code to save local array back to database with custom edit script
  44. How to Create a Confirm Dialog Box Before Submit a Change?

Feedback and Knowledge Base