PDA

View Full Version : Grid question again



sutee84
26 Jan 2011, 10:47 AM
Hi All!

I have a problem with my grid(a new other one) again.
I made a new grid, the datastore,the reader, the php file what read and post the datas, and everything, but the datas doesn't seem in the grid.
I check the headers in firebug, and the datas from the php file seem in the header, but not seem in the grid, and I don't know what is the problem.
The js code:


<?php
session_start();
include_once('../include/functions.php');
db_connect();
?>
<script type="text/javascript">
Ext.onReady(function(){
var grid_width = Ext.get('user_table').getWidth();
var grid_height = Ext.get('user_table').getHeight();

var UserReader = new Ext.data.JsonReader({
root:'user_results',
totalProperty:'user_total',
id:'UserReader',
ields:[
{name:'id',type:'string',mapping:'id'},
{name:'user_name',type:'string',mapping:'user_name'},
{name:'full_name',type:'string',mapping:'full_name'},
{name:'workplace',type:'string',mapping:'workplace'},
{name:'access_level',type:'string',mapping:'access_level'},
{name:'last_login',type:'string',mapping:'last_login'}
]
});

var UserStore = new Ext.data.Store({
id:'UserStore',
proxy: new Ext.data.HttpProxy({
url: './pages/user_store.php',
method: 'POST'
}),
stateful:true,
reader: UserReader,
remoteSort:true,
baseParams:{start:0,limit:25,task:'Listing'},
sortInfo:{field:'full_name',direction:'ASC'}
});

var UserColumnModel = new Ext.grid.ColumnModel(
[{
header: 'Azonosító',
dataIndex: 'id',
sortable: true,
width: 80
},{
header: 'Felhasználónév',
dataIndex: 'user_name',
width: 150,
sortable: true
},{
header: 'Teljes név',
dataIndex: 'full_name',
sortable: true,
width: 200
},{
header: 'Munkahely',
dataIndex: 'workplace',
sortable: true,
width: 200
},{
header: 'Hozzáférési szint',
dataIndex: 'access_level',
sortable: true,
width: 120
},{
header: 'Utolsó belépés',
dataIndex: 'last_login',
sortable: true,
width: 100
}]
);

var UserPagingBar = new Ext.PagingToolbar({
pageSize: 25,
store: UserStore,
beforePageText:'Oldal',
afterPageText:'- {0}',
firstText:'Elejére',
lastText:'Végére',
nextText:'Következ?',
prevText:'El?z?',
refreshText:'Frissítés',
displayInfo: true,
displayMsg: 'Megjelenítve {0} - {1}, összesen: {2}',
emptyMsg: "Nincs megjelenítend? információ!",
items:[
'-', {
text: 'Új felhasználó',
handler: function(){

}
}]

});

var UserGrid = new Ext.grid.GridPanel({
id: 'UserGrid',
store: UserStore,
cm: UserColumnModel,
autoWidth: true,
width: grid_width,
height: grid_height,
title:'Felhasználók',
bbar: UserPagingBar,
listeners:
{
scope: this,
afterrender: function(grd)
{
var cm = grd.getColumnModel();
Ext.each(cm.config, function(col){
col.sortable = true;
});
}
}
});

UserGrid.render('user_table');
UserStore.load();
});
</script>
<div id="user_table" style="width:100%;height:100%;"></div>

And the php file (what read from the datas from the database)

<?php
session_start();
include_once('../include/functions.php');
db_connect();

$task = isset($_REQUEST['task']) ? $_REQUEST['task'] : 'Listing';
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$count = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'full_name';
$dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'ASC';

if($task=='Listing'){
$query = "SELECT users.id as id,users.user_name as user_name,users.full_name as full_name,workplaces.name as workplace,access_levels.name as access_level,users.last_login as last_login FROM users,access_levels,workplaces WHERE users.access_level=access_levels.id AND users.workplace_id=workplaces.id AND users.workplace_id='{$_SESSION['workplace_id']}'";
if ($sort != "") {
$query .= " ORDER BY ".$sort." ".$dir;
}
$query .= " LIMIT ".$start.",".$count;
loging($_SESSION['user_id'],$_SESSION['workplace_id'],time(),$_SERVER['PHP_SELF'],"$query");
$totals = mysql_result(mysql_query("SELECT COUNT(*) FROM users WHERE workplace_id = '{$_SESSION['workplace_id']}'"),0,0);
$result = mysql_query($query);
$nbrows = mysql_num_rows($result);
if($nbrows>0){
$i=0;
while($rec = mysql_fetch_array($result)){
$rec["last_login"] = date("Y-m-d, H:i:s",$rec["last_login"]);
$arr[$i]["id"] = $rec["id"];
$arr[$i]["user_name"] = $rec["user_name"];
$arr[$i]["full_name"] = utf8_encode($rec["full_name"]);
$arr[$i]["workplace"] = utf8_encode($rec["workplace"]);
$arr[$i]["access_level"] = utf8_encode($rec["access_level"]);
$arr[$i]["last_login"] = $rec["last_login"];
$i++;
}
$jsonresult = json_encode($arr);
echo '({"user_total":"'.$totals.'","user_results":'.$jsonresult.'})';
} else {
echo '({"user_total":"0", "user_results":""})';
}
}

if($task=='Add'){
$szoveg = $_REQUEST["szoveg"];
$today = date("Y-m-d");
$now = date("H:i:s");
$q = "INSERT INTO feeds VALUES('','{$_SESSION['user_id']}',".time().",'{$_SESSION['workplace_id']}','$szoveg')";
mysql_query($q);
if(mysql_insert_id)echo "{succes:true}";else echo "{succes:false}";
}
?>

The headers:
Sent:

dir ASC
limit 25
sort full_name
start 0
task Listing

sort=full_name&dir=ASC&start=0&limit=25&task=Listing
Received:

({"user_total":"1","user_results":[{"id":"1","user_name":"sutee84","full_name":"Adminisztr\u00c3\u00a1tor","workplace":"Cinema City - Szeged","access_level":"Adminisztr\u00c3\u00a1tor","last_login":"2011-01-26, 19:33:26"}]})

sutee84
27 Jan 2011, 8:42 AM
I checked it with Illumination, and it seems, that the datastore is empty, but I don't know why, because in the header the datas seem as it sent.

sutee84
29 Jan 2011, 2:26 AM
Hi Everybody!

Fortunately today I found the bug in the code (I typed ileds, except fields in the reader block), so now it works fine.

Thanks!