Thank you very much for your close review.
It was the setColModel that I’d commented out in the process of trying out variations. With that now active, the grid responds as it should. All the rest of the code is fine, and now I can fine tune that.
Jay
I think I’m very close to a solution — as you note, the code appears correct.
But, it’s not working. I really need to resolve this. I’ve studied the various documents and put together what seems to be the correct approach. But, I’m at a loss as to what approaches will lead to a solution.
TIA for your assistance.
RE: Method 1.
I recognize there are potential issues with using $_REQUEST. Hence, the name of the variable.
IN RE: whether the parameter is passed, that should handled correctly by the following code, shouldn’t it be?
$jvs_user_id = $_REQUEST[‘jvs_user_id’] ;
$param1 = (isset($jvs_user_id)) ? $jvs_user_id : $USER->id ;
..
$grid->setUrl(‘grid_center.php?jvs_user_id=’.$param1);
On the first execution, the $_REQUEST should not have the jvs_user_id value, but the $USER->id, set by the Moodle environment, should be set. This is then assigned to $param1 and passed to the $_GET variable.
On the 2nd execution at invocation, as a result, the $_REQUEST will have the variable value set and will be used to set the $param1 variable
$grid->SelectCommand = ‘SELECT id, ‘ .
..
‘FROM mdl_centerstatus ‘ .
“WHERE user_id = ” . $param1 ;
When I generate my own log file and store the resulting SQL statement to it, on the second call, it is properly structured with the WHERE clause. And, when I bring that into phpMyAdmin, the query returns the correct row.
However, this is what I get in the jqGrid.log file:
Executed 1 query(s) – 2015-05-18 13:30:40
Array
(
[0] => Array
(
[time] => 2015-05-18 13:30:40
[query] => SELECT id, user_id, cohort_id, cohort_name, date_course_complete, gospel_pres_prv_yr, gospel_pres_m_1, gospel_pres_m_2, gospel_pres_m_3, gospel_pres_m_4, gospel_pres_m_5, gospel_pres_m_6, gospel_pres_tot_m_6, preg_test_prv_yr, preg_test_m_1, preg_test_m_2, preg_test_m_3, preg_test_m_4, preg_test_m_5, preg_test_m_6, preg_test_tot_m_6, commit_prv_yr, commit_m_1, commit_m_2, commit_m_3, commit_m_4, commit_m_5, commit_m_6, commit_tot_m_6, complete_date_m_6, grant_date FROM mdl_centerstatus WHERE user_id = ? ORDER BY cohort_name asc LIMIT 0, 10
[data] => Array
(
[0] =>
)
[types] =>
[fields] =>
[primary] =>
[input] =>
)
)
It appears to me that the SQL statement is executed only once.
Why is that?
Here’s the $_SESSION method.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
<?php require_once'jq-config.php'; // include the jqGrid Class require_once ABSPATH."php/PHPSuito/jqAutocomplete.php"; require_once ABSPATH."php/PHPSuito/jqCalendar.php"; require_once ABSPATH."php/PHPSuito/jqGrid.php"; // include the driver class require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // Create the jqGrid instance $grid = new jqGridRender($conn); $param1 = array ($_SESSION['jvs_user_id'] ); // set the ouput format to json $grid->dataType = 'json'; $grid->table ="mdl_centerstatus"; $grid->setPrimaryKeyId("id"); $grid->SelectCommand = 'SELECT id, ' . 'user_id, ' . 'cohort_id, ' . 'cohort_name, ' . 'date_course_complete, ' . 'gospel_pres_prv_yr, ' . 'gospel_pres_m_1, ' . 'gospel_pres_m_2, ' . 'gospel_pres_m_3, ' . 'gospel_pres_m_4, ' . 'gospel_pres_m_5, ' . 'gospel_pres_m_6, ' . 'gospel_pres_tot_m_6, ' . 'preg_test_prv_yr, ' . 'preg_test_m_1, ' . 'preg_test_m_2, ' . 'preg_test_m_3, ' . 'preg_test_m_4, ' . 'preg_test_m_5, ' . 'preg_test_m_6, ' . 'preg_test_tot_m_6, ' . 'commit_prv_yr, ' . 'commit_m_1, ' . 'commit_m_2, ' . 'commit_m_3, ' . 'commit_m_4, ' . 'commit_m_5, ' . 'commit_m_6, ' . 'commit_tot_m_6, ' . 'complete_date_m_6, ' . 'grant_date ' . 'FROM mdl_centerstatus ' . "WHERE user_id = ? " ; $grid->setUrl('grid_center.php'); $grid->setColModel(null, $param1); $grid->cacheCount = true; $grid->setGridOptions(array( "caption"=>"Center Status", "rowNum"=>10, "sortname"=>"cohort_name", "hoverrows"=>true, "height"=> 300, "width"=> 700, "shrinkToFit"=> false, "rowList"=>array(10,20,50), "postData"=>array("grid_recs"=>776) )); $grid->setColProperty("id", array("label"=>"ID", "width"=>30, "editable"=>false, "hidden"=>true, "frozen"=>true)); $grid->setColProperty("user_id", array("label"=>"User", "width"=>30, "editable"=>false, "frozen"=>true)); $grid->setColProperty("cohort_id", array("label"=>"Cent ID", "width"=>40, "editable"=>false, "frozen"=>true)); $grid->setColProperty("cohort_name", array("label"=>"Name", "width"=>130, "editable"=>false, "frozen"=>true)); $grid->setColProperty("date_course_complete", array("label"=>"Completed", "width"=>70, "editable"=>false, "frozen"=>true)); $grid->setColProperty("gospel_pres_prv_yr", array("label"=>"Gosp Lst", "width"=>60, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_prv_yr", array("label"=>"Preg Lst", "width"=>60, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_prv_yr", array("label"=>"Comm Lst", "width"=>60, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_1", array("label"=>"Gosp 1", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_1", array("label"=>"Preg 1", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_1", array("label"=>"Comm 1", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_2", array("label"=>"Gosp 2", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_2", array("label"=>"Preg 2", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_2", array("label"=>"Comm 2", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_3", array("label"=>"Gosp 3", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_3", array("label"=>"Preg 3", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_3", array("label"=>"Comm 3", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_4", array("label"=>"Gosp 4", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_4", array("label"=>"Preg 4", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_4", array("label"=>"Comm 4", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_5", array("label"=>"Gosp 5", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_5", array("label"=>"Preg 5", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_5", array("label"=>"Comm 5", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_m_6", array("label"=>"Gosp 6", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("preg_test_m_6", array("label"=>"Preg 6", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("commit_m_6", array("label"=>"Comm 6", "width"=>50, "editable"=>true, "align"=>"right")); $grid->setColProperty("gospel_pres_tot_m_6", array("label"=>"Gosp 6 Tot", "width"=>70, "editable"=>false, "align"=>"right")); $grid->setColProperty("preg_test_tot_m_6", array("label"=>"Preg 6 Tot", "width"=>70, "editable"=>false, "align"=>"right")); $grid->setColProperty("commit_tot_m_6", array("label"=>"Comm 6 Tot", "width"=>70, "editable"=>false, "align"=>"right")); $grid->setColProperty("complete_date_m_6", array("label"=>"6 Mon Complete", "width"=>70, "editable"=>false,)); $grid->setColProperty("grant_date", array("label"=>"Grant Date", "width"=>70, "editable"=>false,)); $grid->setColProperty('date_course_complete', array("formatter"=>"date", "formatoptions"=>array("reformatAfterEdit"=>true, "srcformat"=>"Y-m-d", "newformat"=>"m-d-Y") ) ); $grid->setColProperty('complete_date_m_6', array("formatter"=>"date", "formatoptions"=>array("reformatAfterEdit"=>true, "srcformat"=>"Y-m-d", "newformat"=>"m-d-Y") ) ); $grid->setColProperty('grant_date', array("formatter"=>"date", "formatoptions"=>array("reformatAfterEdit"=>true, "srcformat"=>"Y-m-d", "newformat"=>"m-d-Y") ) ); $grid->setDatepicker("date_course_complete",array("buttonOnly"=>false)); $grid->setDatepicker("complete_date_m_6",array("buttonOnly"=>false)); $grid->setDatepicker("grant_date",array("buttonOnly"=>false)); // Enjoy $grid->navigator = true; $grid->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>false, "search"=>true)); // Close the dialog after editing $grid->setNavOptions('edit',array("closeAfterEdit"=>true,"editCaption"=>"Update","bSubmit"=>"Update")); // Call the frozen cols method $grid->callGridMethod('#grid', 'setFrozenColumns'); $grid->exportfile = 'Report.xls'; // calculate the monthsum field $calcs = <<< CALCS function(postdata) { postdata['gospel_pres_tot_m_6'] = parseInt(postdata['gospel_pres_m_1']) + parseInt(postdata['gospel_pres_m_2']) + parseInt(postdata['gospel_pres_m_3']) + parseInt(postdata['gospel_pres_m_4']) + parseInt(postdata['gospel_pres_m_5']) + parseInt(postdata['gospel_pres_m_6']); postdata['preg_test_tot_m_6'] = parseInt(postdata['preg_test_m_1']) + parseInt(postdata['preg_test_m_2']) + parseInt(postdata['preg_test_m_3']) + parseInt(postdata['preg_test_m_4']) + parseInt(postdata['preg_test_m_5']) + parseInt(postdata['preg_test_m_6']); postdata['commit_tot_m_6'] = parseInt(postdata['commit_m_1']) + parseInt(postdata['commit_m_2']) + parseInt(postdata['commit_m_3']) + parseInt(postdata['commit_m_4']) + parseInt(postdata['commit_m_5']) + parseInt(postdata['commit_m_6']); return postdata; } CALCS; $grid->setNavEvent("edit", "serializeEditData", $calcs); $grid->renderGrid('#grid','#pager',true, null, $param1, true,true); ?> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top