View Full Version : GridPanel: Shows Only one record[last record form JSON data]

6 Aug 2009, 7:41 AM

This is a strange behavior i don't know what is happening, my grid panel only shows one record.

following is my PHP file Code:

$id = $_POST['id1'];
$result = mysql_query("SELECT customerID, cdName, cdEmail, cdPhone, cdCell FROM tblcontacts WHERE customerID = ".$id);
If (mysql_num_rows($result) > 0) {

while ($obj = mysql_fetch_object($result)) {
$arr[] = $obj;
Echo '{rows:'.json_encode($arr).'}';
Echo '{rows:[]}';

?>following is the JSON output for the same:

{rows:[{"customerID":"6","cdName":"HELPDESK","cdEmail":"[email protected]","cdPhone":" (62) 21 3000-3749 ","cdCell":"(62) 3000 8686"},{"customerID":"6","cdName":"MUHAMMAD ISWANTO","cdEmail":"[email protected]","cdPhone":"(62) 816-92-4045 ","cdCell":"N\/A"},{"customerID":"6","cdName":"ARIADI SULISTYO","cdEmail":"[email protected]","cdPhone":"(65) 9339-5977","cdCell":"(65) 9339-5977"}]}

,following is my store for the grid:

var dsCodByid = new Ext.data.Store({
autoDestroy: true,
reader: new Ext.data.JsonReader({
root: 'rows',
id: 'customerID',
proxy: new Ext.data.HttpProxy({
url: 'include/getCodById.php'
});following is my grid definition:

var grid = new Ext.grid.GridPanel({
title: 'Contact Details',
store: dsCodByid,
stripeRows: true,
animCollapse: true,
columnLines: true,
columns: [
{header: 'Contact Name', dataIndex: 'cdName', width: 250},
{header: 'Email Address', dataIndex: 'cdEmail', width: 250},
{header: 'Office Phone', dataIndex: 'cdPhone', width: 250},
{header: 'Cell Phone', dataIndex: 'cdCell', width: 250},
});and following is how I am loading the store:

grid.store.reload({params:{id1: rId}});
dsCodByid.on("load", function() {
var el = grid.getGridEl();
if (dsCodByid.getTotalCount() == 0 && typeof el == 'object') {
el.mask('<b><font color="red">No Contact Details Found</font></b>', 'x-mask');


Now as JSON data shows us the three records under rows but my gridpanel only show the last one.

Please help in this regard,

6 Aug 2009, 7:47 AM
CustomerID is being setup as an 'id' column, which is a unique identifier. Since your data has '6' as the CustomerID for every row of data.....well, you get it by now.

6 Aug 2009, 7:49 AM
Gr8 , got it, I love this team , No other forum or framework has such support .

Thanks Man