Guest User

jqgrid

a guest
Aug 24th, 2011
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.97 KB | None | 0 0
  1. <?php
  2. require_once '../../../jq-config.php';
  3. // include the jqGrid Class
  4. require_once ABSPATH."php/jqGrid.php";
  5. // include the driver class
  6.  
  7. // Create the jqGrid instance
  8. $grid = new jqGridRender();
  9. // Lets create the model manually and set the formatters
  10. $Model = array(
  11.     array("name"=>"ID","width"=>50),
  12.     array("name"=>"PhotoFileName","width"=>100),
  13.     array("name"=>"Photo","width"=>100,"formatter"=>"js:formatImage", "unformat"=>"js:unformatImage"),
  14.     array("name"=>"Rating","sorttype"=>"integer","formatter"=>"js:formatRating","unformat"=>"js:unformatRating")
  15. );
  16. // Let the grid create the model
  17. $grid->setColModel($Model);
  18. // Set grid option datatype to be local
  19. $grid->setGridOptions(array("datatype"=>"local", "width"=>400,"height"=>350));
  20. //We can add data manually using arrays
  21. $data = array();
  22. for($i=0;$i<9;$i++)
  23. {
  24.     $data[] = array("ID"=>$i+1,"PhotoFileName"=>($i+1).".jpg","Photo"=>($i+1).".jpg", "Rating"=>rand(-20,30));
  25. }
  26. // Let put it using the callGridMethod
  27. $grid->callGridMethod("#grid", 'addRowData', array("ID",$data));
  28. // We can put JS from php
  29. $custom = <<<CUSTOM
  30. function formatImage(cellValue, options, rowObject) {
  31.     var imageHtml = "<img src='images/" + cellValue + "' originalValue='" + cellValue + "' />";
  32. return imageHtml;
  33. }
  34. function unformatImage(cellValue, options, cellObject) {
  35.     return $(cellObject.html()).attr("originalValue");
  36. }
  37. function formatRating(cellValue, options, rowObject) {
  38.     var color = (parseInt(cellValue) > 0) ? "green" : "red";
  39.     var cellHtml = "<span style='color:" + color + "' originalValue='" +
  40.                    cellValue + "'>" + cellValue + "</span>";
  41.     return cellHtml;
  42. }
  43. function unformatRating(cellValue, options, cellObject) {
  44.     return $(cellObject.html()).attr("originalValue");
  45. }
  46. CUSTOM;
  47. // Let set the code which is executed at end
  48. $grid->setJSCode($custom);
  49. $grid->renderGrid('#grid','#pager',true, null, null, true,true);
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment