PDA

View Full Version : My Data from table didn't show



anzfreak
8 Oct 2009, 11:52 PM
dear friends, i'm using extjs grid to show my table from database but it didn't show up.
I'm using postgreSQL. I'm wonder what's wrong with my code.

here ext code


Ext.onReady(function(){
Ext.QuickTips.init();

var SimpleDataStore = new Ext.data.JsonStore({
root: 'results',
totalProperty: 'total',
url: 'wo.php',
/*proxy: new Ext.data.HttpProxy({
url: 'wo.php',
method: 'POST'
}),*/
fields:
[{name: 'nom', type: 'int'},
{name: 'wono', type: 'string'},
{name: 'title', type: 'string'},
{name: 'br_descr', type: 'string'},
{name: 'wotype', type: 'int'},
{name: 'attach', type: 'string'},
{name: 'issuedt2', type: 'string'},
{name: 'issuedby', type: 'string'},
{name: 'dept', type: 'string'},
{name: 'priority', type: 'string'},
{name: 'duedt', type: 'date'},
{name: 'clid', type: 'string'},
{name: 'prodid', type: 'string'},
{name: 'moduleid', type: 'string'},
{name: 'projid', type: 'string'},
{name: 'csissue', type: 'string'},
{name: 'chgreg', type: 'string'},
{name: 'resolution', type: 'string'},
{name: 'wogroup', type: 'string'},
{name: 'complex', type: 'string'},
{name: 'impact', type: 'string'},
{name: 'estday', type: 'string'},
{name: 'estfinish', type: 'string'},
{name: 'assgn', type: 'string'},
{name: 'keyword1', type: 'string'},
{name: 'keyword2', type: 'string'},
{name: 'refwono', type: 'string'},
{name: 'rftdt', type: 'string'},
{name: 'dbch', type: 'string'},
{name: 'status', type: 'string'},
{name: 'tester', type: 'string'},
{name: 'projstat', type: 'string'},
{name: 'recdt', type: 'string'},
{name: 'wkprtsts', type: 'string'},
{name: 'issuedt', type: 'string'},
{name: 'csrno', type: 'string'},
{name: 'sos', type: 'string'},
{name: 'groupflag', type: 'string'},
{name: 'regby', type: 'string'},
{name: 'regdt', type: 'string'},
{name: 'tester', type: 'string'}
],
sortInfo: {field: 'wono', directions: "DESC"}
});


var SimpleColumnModel = new Ext.grid.ColumnModel([
{ header: 'Wo Number',
dataIndex: 'wono',
width: 250
},{
header: 'Title',
dataIndex: 'title',
width: 250
},{
header: 'Product ID',
dataIndex: 'prodid',
id: 'prod',
renderer: function(prod){
return '<pre >' + prod + '</pre>';
},
width: 80
},{
header: 'Module ID',
dataIndex: 'moduleid',
width: 80
},{
header: 'Issued By',
dataIndex: 'issuedby',
width: 100
},{
header: 'Issued Date',
dataIndex: 'issuedt',
width: 100
},{
header: 'Reg By',
dataIndex: 'regby',
width: 100
},{
header: 'Reg Date',
dataIndex: 'regdt',
width: 100
},{
header: 'Tester 1',
dataIndex: 'tester',
width: 100
},{
header: 'Tester 2',
dataIndex: 'tester2',
width: 100
},{
header: 'Exp. 1<sup>st</sup> RFT Date',
dataIndex: 'duedt',
width: 100
},{
header: 'Due date',
dataIndex: 'rftdt',
width: 100
},{
header: 'CS Issue',
dataIndex: 'csissue',
width: 100
},{
header: 'Assign To',
dataIndex: 'assgn',
width: 70
},{
header: 'Status',
dataIndex: 'status',
width: 70
},{
header: 'CLS date',
dataIndex: '',
width: 100
},{
header: 'SOS',
dataIndex: 'sos',
width: 70
},{
header: 'FIX',
dataIndex: '',
width: 70
},{
header: 'CRQ',
dataIndex: '',
width: 70
}
]);
SimpleColumnModel.defaultSortable= true;


var SimpleListingEditorGrid = new Ext.grid.GridPanel({
title: 'Work Order',
store: SimpleDataStore,
cm: SimpleColumnModel,
viewConfig: {
forceFit: true
},
frame: true,
stripeRows: true,
collapsible: true,
animCollapse: true,
autoWidth: true,
autoHeight: true,

bbar: new Ext.PagingToolbar({ //paging grid
pageSize: 20,
store: SimpleDataStore,
displayInfo: true,
displayMsg: 'Displaying data {0} - {1} of {2}',
emptyMsg: "No data to display"
})
});
SimpleDataStore.load({params:{start:0,limit:20}});
var myPanel = new Ext.Panel({
autoScroll: true,
renderTo: 'wo',
items: [ SimpleListingEditorGrid ]
});

});


and here is the php code


<?
include "JSON.php";
//include "koneksi.php";

$conn = pg_connect("host='localhost' port=5432 dbname='waroeng' user='waroeng' password='waroengadm'");
if (!$conn) {
die("Error in connection: " . pg_last_error());
}

$query = "select wono from wo order by nom desc";
$hasil = pg_query($conn, $query);
$nbrows = pg_num_rows($hasil);
$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
$limit = $query." limit ".$start.",".$end;
$result = pg_query($conn, $limit);

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

function JEncode($arr){
if (version_compare(PHP_VERSION,"5.2","<"))
{
require_once("JSON.php");
$json = new Services_JSON();
$data=$json->encode($arr);
} else {
$data = json_encode($arr);
}
return $data;
}
}

?>

Condor
9 Oct 2009, 12:01 AM
Debug.

1. Does the server return the expected JSON data (use Firebug Net tab or Fiddler)?
2. Does the store fire an exception event?
3. Does the store fire a load event?

anzfreak
9 Oct 2009, 12:07 AM
No, it's just return blank/nothing even in firebug

Condor
9 Oct 2009, 3:06 AM
So this is a PHP problem? This might not be the best forum to ask PHP questions...

anzfreak
9 Oct 2009, 3:17 AM
it's a php problem?? is my json right?

Animal
9 Oct 2009, 3:25 AM
Have you looked at the JSON?

anzfreak
11 Oct 2009, 7:34 PM
dear friends, if i change mysql statement to "select * from wo" return :

({"total":"7745","results":null})

hallikpapa
11 Oct 2009, 10:23 PM
the results: null is telling you there is NO records coming back. it should look similar to

{"total":"7745","results":{yourDataIndexName:dataValue.....}}

Your PHP is not returning anything, which is where your problem lies, not in extjs

Animal
11 Oct 2009, 11:36 PM
The root must be an Array:



{"total":"7745","results":[{yourDataIndexName:dataValue.....}]}