View Full Version : Dynamic Columns in a Grid (value from a form)

26 Jun 2011, 9:32 AM
Hi, brothers!
Now I have have to load data into a grid: I select data from a postgresql database and it works very well. The query is like this: $query = "SELECT * FROM position WHERE plaque='value'"; (understand 'value' is a value in my table 'position') And it works.

But I want this value to be a variable (for exemple has this query: $query = "SELECT * FROM position WHERE plaque='$var'";) where $var is gotten from a form (it means I have a form and a field of this form I type a value and get this value in the variable $var like: $var=$_POST['idfield'];). But now it doen't work.

Then I need a help from you.
This is the code for the form:
items: [{
fieldLabel: 'Jour',
name: 'idfield'
buttons: [{
text: 'Modifier',
handler: function() {
gridForm.getForm().getEl().dom.action = 'reporting/?eid=ajout/horaire';
gridForm.getForm().getEl().dom.method = 'POST';
This is the part of the form definition and I tested it is works.

The entire php code is this:


include '../../pgbconnection.php';


$task = '';
if ( isset($_POST['task'])){
$task = $_POST['task'];
case "LISTING":

function getList2()
{global $jr;
echo $jr;}
function getList()
global $jr;
$query = "SELECT * FROM position WHERE plaque='$jr'";
$result = pg_query($query);
$nbrows = pg_num_rows($result);
while($rec = pg_fetch_array($result)){

$arr[] = $rec;
$jsonresult = JEncode($arr);
echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
} else {
echo '({"total":"0", "results":""})';

function codeDate ($date) {
$tab = explode ("-", $date);
$r = $tab[1]."/".$tab[2]."/".$tab[0];
return $r;

function JEncode($arr){
if (version_compare(PHP_VERSION,"5.2","<"))
$json = new Services_JSON();
} else
$data = json_encode($arr);
return $data;

And the grid code:
var store;
var colModel;



store = new Ext.data.Store({
id: 'store',
proxy: new Ext.data.HttpProxy({
url: 'reporting/ajout/boitier2.php', // File to connect to
method: 'POST'
baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request and asks for listing
reader: new Ext.data.JsonReader({
// we tell the datastore where to get his data from
root: 'results',
totalProperty: 'total',
id: 'id'

{name: 'jour', type: 'date', mapping: 'jour'},
{name: 'temps', type: 'string', mapping: 'temps'},
{name: 'plaque', type: 'string', mapping: 'plaque'},

sortInfo:{field: 'longitude', direction: "ASC"}
store.load(); // Load the data

colModel = new Ext.grid.ColumnModel(
header: 'Jour',
dataIndex: 'jour',
width: 100,
renderer: Ext.util.Format.dateRenderer('d/m/Y'),
hidden: false
header: 'Heure',
readOnly: true,
dataIndex: 'temps',
width: 100,
hidden: false
header: 'Boit',
readOnly: true,
dataIndex: 'plaque',
width: 50,
hidden: false
colModel.defaultSortable= true;

var grid = new Ext.grid.GridPanel({
height : 300,
width : 600,
tbar : [],
title : 'title',
store : store,
stripeRows : true,
defaultSortable : true,
xtype: 'grid',
store: store,
cm: colModel,
autoExpandColumn: 'columnID',
border: true,


Now I thing the error should be in the php code because:
1) When i set $jr='a value'; instead of $jr=$_POST['plaque']; it works well
2) When i maintain $jr=$_POST['plaque'], the function getList2() returns the value but the function getList() which provides the values to the grid doesn't work.

Please, what can i do for this function, getList()? Can any one provide as answer to this issue?

Thank you!

26 Jun 2011, 10:35 AM
At a quick glance, where is 'plaque' being set in the _POST?

I mean, shouldn't you be setting gridForm.getForm().params to include the form value you want to pass?
Also, how do you plan to submit via _POST to a URL/action containing a _GET var?

It might help to have all of the form code, but I don't see id: 'plaque' set anywhere, so that it transfers over in the _POST/action. Have you looked in Firebug to see what is being sent to the server?

29 Jun 2011, 1:22 PM

Finally I found an error in the php code! Now it's working

Thanks again!