utherwayn
06-06-2007, 06:00 AM
So I have been trying to modify an existing tutorial: Basics of Paging With the Grid Component.
I am using his database but using my own script and trying to convert to a HttpProxy instead of a ScriptTagProxy. Seems like a really simple task and im sort of ashamed that I couldn't think my way through it however I am sort of new to javascript. Below is my PHP script and JS
$link = mysql_pconnect("test-db.vinylfox.com", "test", "testuser") or die("Could not connect");
mysql_select_db("test") or die("Could not select database");
$sql_count = "SELECT id, name, title, hire_date, active FROM random_employee_data";
$sql = $sql_count . " LIMIT ".$_GET['start'].", ".$_GET['limit'];
$rs_count = mysql_query($sql_count);
$rows = mysql_num_rows($rs_count);
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs))
{
$arr[] = $obj;
}
Echo $_GET['callback'].'({"total":"'.$rows.'","results":'.json_encode($arr).'})';
Ext.onReady(function(){
var ds = new Ext.data.Store({
// HttpProxy should be used here
proxy: new Ext.data.HttpProxy({
url: 'http://sandbox.andylogic.com/extjs/grid-paging-data.php'
}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
}, [
{name: 'employee_name', mapping: 'name'},
{name: 'job_title', mapping: 'title'},
{name: 'hire_date', mapping: 'hire_date', type: 'date', dateFormat: 'm-d-Y'},
{name: 'is_active', mapping: 'active'}
])
});
var cm = new Ext.grid.ColumnModel([{
id: 'name',
header: "Name",
dataIndex: 'employee_name',
width: 100
},{
header: "Title",
dataIndex: 'job_title',
width: 170
},{
header: "Hire Date",
dataIndex: 'hire_date',
width: 70,
renderer: Ext.util.Format.dateRenderer('n/j/Y')
},{
header: "Active",
dataIndex: 'is_active',
width: 50
}]);
var grid = new Ext.grid.Grid('grid-paging', {
ds: ds,
cm: cm,
autoExpandColumn: 'name'
});
grid.render();
var gridFoot = grid.getView().getFooterPanel(true);
var paging = new Ext.PagingToolbar(gridFoot, ds, {
pageSize: 25,
displayInfo: true,
displayMsg: 'Displaying results {0} - {1} of {2}',
emptyMsg: "No results to display"
});
ds.load({params:{start:0, limit:25}});
});
This is essentially exactly the same code as his with the only exception being that I changed ScriptTagProxy to HttpProxy. I looked up in the reference documentation and they both seem to accept the same format yet with HttpProxy the script doesn't work and with ScriptTagProxy it does.
Firebug provides me with the following PHP error from the server
<b>Warning</b>: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>
/home/.ann/utherwayn/sandbox.andylogic.com/extjs/grid-paging-data.php</b> on line <b>15</b><br />
({"total":"200","results":null})
So it basically says it is getting no data. I have tracked it down to the ds.load() line in my JS, for some reason it seems the parameters are not being passed in correctly which leads me to believe that unless there is a bug which I highly doubt there is in what has to be a commonly used component, that my javascript too weak and they actually DONT accept the same parameter format for load.
Can someone let me know which is the case? Is this a bug or is this my own failed understanding of javascript?
I am using his database but using my own script and trying to convert to a HttpProxy instead of a ScriptTagProxy. Seems like a really simple task and im sort of ashamed that I couldn't think my way through it however I am sort of new to javascript. Below is my PHP script and JS
$link = mysql_pconnect("test-db.vinylfox.com", "test", "testuser") or die("Could not connect");
mysql_select_db("test") or die("Could not select database");
$sql_count = "SELECT id, name, title, hire_date, active FROM random_employee_data";
$sql = $sql_count . " LIMIT ".$_GET['start'].", ".$_GET['limit'];
$rs_count = mysql_query($sql_count);
$rows = mysql_num_rows($rs_count);
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs))
{
$arr[] = $obj;
}
Echo $_GET['callback'].'({"total":"'.$rows.'","results":'.json_encode($arr).'})';
Ext.onReady(function(){
var ds = new Ext.data.Store({
// HttpProxy should be used here
proxy: new Ext.data.HttpProxy({
url: 'http://sandbox.andylogic.com/extjs/grid-paging-data.php'
}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
}, [
{name: 'employee_name', mapping: 'name'},
{name: 'job_title', mapping: 'title'},
{name: 'hire_date', mapping: 'hire_date', type: 'date', dateFormat: 'm-d-Y'},
{name: 'is_active', mapping: 'active'}
])
});
var cm = new Ext.grid.ColumnModel([{
id: 'name',
header: "Name",
dataIndex: 'employee_name',
width: 100
},{
header: "Title",
dataIndex: 'job_title',
width: 170
},{
header: "Hire Date",
dataIndex: 'hire_date',
width: 70,
renderer: Ext.util.Format.dateRenderer('n/j/Y')
},{
header: "Active",
dataIndex: 'is_active',
width: 50
}]);
var grid = new Ext.grid.Grid('grid-paging', {
ds: ds,
cm: cm,
autoExpandColumn: 'name'
});
grid.render();
var gridFoot = grid.getView().getFooterPanel(true);
var paging = new Ext.PagingToolbar(gridFoot, ds, {
pageSize: 25,
displayInfo: true,
displayMsg: 'Displaying results {0} - {1} of {2}',
emptyMsg: "No results to display"
});
ds.load({params:{start:0, limit:25}});
});
This is essentially exactly the same code as his with the only exception being that I changed ScriptTagProxy to HttpProxy. I looked up in the reference documentation and they both seem to accept the same format yet with HttpProxy the script doesn't work and with ScriptTagProxy it does.
Firebug provides me with the following PHP error from the server
<b>Warning</b>: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>
/home/.ann/utherwayn/sandbox.andylogic.com/extjs/grid-paging-data.php</b> on line <b>15</b><br />
({"total":"200","results":null})
So it basically says it is getting no data. I have tracked it down to the ds.load() line in my JS, for some reason it seems the parameters are not being passed in correctly which leads me to believe that unless there is a bug which I highly doubt there is in what has to be a commonly used component, that my javascript too weak and they actually DONT accept the same parameter format for load.
Can someone let me know which is the case? Is this a bug or is this my own failed understanding of javascript?