PDA

View Full Version : Data not load in my grid



jordi
1 May 2007, 5:08 PM
Hello and sorry for my english

My problem is symple. The grid render and work Ok whit all functionality but the data not load in the grid.

Any suggestion?? Is the data.Store ???

Thanks and regards.


My dode:

JavaScript-

Ext.onReady(function(){

function formatBoolean(value){
return value ? 'Yes' : 'No';
};

function formatDate(value){
return value ? value.dateFormat('M d, Y') : '';
};
// shorthand alias
var fm = Ext.form, Ed = Ext.grid.GridEditor;


var SQL = "SELECT Referencia,Nom,Direccio,Poblacio,Provincia,Pais,Telefon,Telefon2,email FROM fotosoler.clients";


// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel([
{
header: "Referencia",
dataIndex: 'Referencia',
width: 100,
align: 'right',
editor: new Ed(new fm.NumberField({
allowBlank: false,
allowNegative: false,
maxValue: 10
}))
},{
header: "Nom",
dataIndex: 'Nom',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Direccio",
dataIndex: 'Direccio',
width: 230,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Poblacio",
dataIndex: 'Poblacio',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Provincia",
dataIndex: 'Provincia',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Pais",
dataIndex: 'Pais',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Telefon",
dataIndex: 'Telefon',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "Telefon2",
dataIndex: 'Telefon2',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
},{
header: "email",
dataIndex: 'email',
width: 130,
editor: new Ed(new fm.TextField({
allowBlank: true
}))
}
]);

// by default columns are sortable
cm.defaultSortable = true;

// this could be inline, but we want to define the regTipus record
// type so we can add records dynamically
var regTipus = Ext.data.Record.create([
{name: 'Referencia', type: 'float'},
{name: 'Nom', type: 'string'},
{name: 'Direccio', type: 'string'},
{name: 'Poblacio', type: 'string'},
{name: 'Provincia', type: 'string'},
{name: 'Pais', type: 'string'},
{name: 'Telefon', type: 'string'},
{name: 'Telefon2', type: 'string'},
{name: 'email', type: 'string'}
]);

// create the Data Store
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'http://localhost/soler/sql_array.php'}),
baseParams: {SQL:SQL},
reader: new Ext.data.JsonReader({root:"rows"}, regTipus)
});

// create the editor grid
var grid = new Ext.grid.EditorGrid('editor-clients', {
ds: ds,
cm: cm,
//selModel: new Ext.grid.RowSelectionModel(),
enableColLock:true
});

var layout = Ext.BorderLayout.create({
center: {
margins:{left:3,top:3,right:3,bottom:3},
panels: [new Ext.GridPanel(grid)]
}
}, 'panell-clients');


// render it
grid.render();


var gridHead = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(gridHead, [{
text: 'Nou registre',
handler : function(){
var p = new regTipus({
Referencia: 0,
Direccio: '',
Poblacio: '',
Provincia: '',
Pais: '',
Telefon: '',
Telefon2: '',
email: ''
//availDate: new Date(),
//indoor: false
});
grid.stopEditing();
ds.insert(0, p);
grid.startEditing(0, 0);
}
}]);

// trigger the data store load
ds.load();
});



PHP - sql_array.php

<?
$connection = mysql_connect("localhost","root","");
$resultat = mysql_query(stripslashes($_REQUEST['SQL']),$connection) ;

if (gettype($resultat) == 'resource') {
$recordset = array();
while ($fila = mysql_fetch_object($resultat)) {
$recordset[] = $fila;
}

header("Content-Type", "text/json");
echo '{"rows":'.json_encode($recordset).'}';
}elseif (gettype($resultat) == false){
echo die("La consulta a fallado sobre ".$resultat." : ".mysql_error());
}

?>

tryanDLS
1 May 2007, 6:13 PM
There are numerous threads regarding data load problems in grids. I suggest you review some of them, then use Firebug to debug your code and verify a) the request is being made and b) the response is coming back and being handled correctly.

jordi
2 May 2007, 6:14 AM
Ok, but, I can tell you that I search intensively and I don't find any
post whith my problem. If you don't want assit my question, I don't disturb
more time.


thanks and regards

jsakalos
2 May 2007, 11:59 AM
Use firebug to see if request was sent to the server, to check if and what arrived from server and/or if there are any errors reported by firebug.

jordi
2 May 2007, 1:36 PM
I was install the Firebug utility and no errors are retourned, but the response tab inform "Loading ..." and any more.

When I install the Ext libraries, I substitute the ext-all.js for the version for jquery generated from the web and satisfy all dependences i my page (jquery.js, dimension.js, ext-jquery-adapter.js and ext-all.js). Is this correct?

... but my doubt is in the code: i utilize the data.Store object correctly?

var ds = new Ext.data.Store({
// load using HTTP - Cridem a l Arxiu PHP i li passem la variable SQL amb la SELECT

proxy: new Ext.data.HttpProxy({url:'http://localhost/soler/sql_array.php'}),
baseParams: {SQL:SQL},
// the return will be JSON, so lets set up a reader
reader: new Ext.data.JsonReader({root:"rows"}, regTipus)
});

. . . . . .

grid.render();

. . . . . .

ds.load();

thanks and regards,


Jordi - Barcelona

exo
2 May 2007, 2:01 PM
Wow, sending a SQL query from your javascript. Talk about security issues. Anyway, shouldnt 'Telefon' be one word? And shouldnt you use mysql_select_db to select a database?

jsakalos
2 May 2007, 3:36 PM
If the response panel of firebug just says Loading... the server haven't sent anything back. Try (on the server): echo "I am here"; and see in firebug if you get this text back.