PDA

View Full Version : Pls help i begin to use infinity grid and i cant see result record after execute



bas_sencha_id
6 Feb 2013, 11:52 AM
i do so (here my exemple http://investsecret.ru/tmp/infinite-scroll.html)
this lib use for experiment only:


JS script:

Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.grid.PagingScroller'
]);


Ext.onReady(function(){
Ext.define('ForumThread', {
extend: 'Ext.data.Model',
fields: [
'title', 'forumtitle', 'forumid', 'username', {
name: 'replycount',
type: 'int'
}, {
name: 'lastpost',
mapping: 'lastpost',
type: 'date',
dateFormat: 'timestamp'
},
'lastposter', 'excerpt', 'threadid'
],
idProperty: 'threadid'
});

// create the Data Store
var store = Ext.create('Ext.data.Store', {
id: 'store',
model: 'ForumThread',
remoteGroup: true,
// allow the grid to interact with the paging scroller by buffering
buffered: true,
leadingBufferZone: 30,
pageSize: 20,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an Ajax proxy would be better
type: 'jsonp',
url: 'index.php',
//url: 'http://www.sencha.com/forum/remote_topics/index.php',
// url: '/index.php',
// url: 'http://investsecret.ru/tmp/index.php',
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true,
// sends single group as multi parameter
simpleGroupMode: true,

// This particular service cannot sort on more than one field, so grouping === sorting.
groupParam: 'sort',
groupDirectionParam: 'dir'
},
sorters: [{
property: 'threadid',
direction: 'ASC'
}],
autoLoad: true,
listeners: {

// This particular service cannot sort on more than one field, so if grouped, disable sorting
groupchange: function(store, groupers) {
var sortable = !store.isGrouped(),
headers = grid.headerCt.getVisibleGridColumns(),
i, len = headers.length;

for (i = 0; i < len; i++) {
headers[i].sortable = (headers[i].sortable !== undefined) ? headers[i].sortable : sortable;
}
},

// This particular service cannot sort on more than one field, so if grouped, disable sorting
beforeprefetch: function(store, operation) {
if (operation.groupers && operation.groupers.length) {
delete operation.sorters;
}
}
}
});

function renderTopic(value, p, record) {
return Ext.String.format(
'<a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a>',
value,
record.data.forumtitle,
record.getId(),
record.data.forumid
);
}

var grid = Ext.create('Ext.grid.Panel', {
width: 700,
height: 500,
collapsible: true,
title: 'ExtJS.com - Browse Forums',
store: store,
loadMask: true,
selModel: {
pruneRemoved: false
},
multiSelect: true,
viewConfig: {
trackOver: false
},
features:[{
ftype: 'grouping',
hideGroupedHeader: false
}],
verticalScroller:{
variableRowHeight: true

},
// grid columns
columns:[{
xtype: 'rownumberer',
width: 50,
sortable: false
},{
tdCls: 'x-grid-cell-topic',
text: "Topic",
dataIndex: 'title',
flex: 1,
renderer: renderTopic,
sortable: true
},{
text: "Author",
dataIndex: 'username',
width: 100,
hidden: true,
sortable: true
},{
text: "Replies",
dataIndex: 'replycount',
align: 'center',
width: 70,
sortable: false
},{
id: 'last',
text: "Last Post",
dataIndex: 'lastpost',
width: 130,
renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
sortable: true,
groupable: false
}],
renderTo: Ext.getBody()
});
});



php script:


<?php

// Make a MySQL Connection
mysql_connect("sever", "user", "passs") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

$start = 1;
if (isset($_REQUEST['start']))
{
$start = $_REQUEST['start'];
}
$limit = 10;
if (isset($_REQUEST['limit'])) {
$limit = $_REQUEST['limit'];
}




$query ="Select
title,
threadid,
username,
userid,
dateline,
postid,
forumtitle,
forumid,
replycount,
lastpost
from test Limit ".$start.", ".$limit;

$result = mysql_query($query)
or die(mysql_error());
//$row = mysql_fetch_assoc($result);

$data = array();

while ($row = mysql_fetch_array($result)) //, MYSQL_ASSOC
{
$data[] = array(
'title' => $row['title'],
'threadid' => $row['threadid'],
'username' => $row['username'],
'userid' => $row['userid'],
'dateline' => $row['dateline'],
'postid' => $row['postid'],
'forumtitle' => $row['forumtitle'],
'forumid' => $row['forumid'],
'replycount' => $row['replycount'],
'lastpost' => $row['lastpost']
);

}

//$cnt = array();
$cnt = count($data);

$myData = array(
"success" => 'true',
"totalCount" => "$cnt",
"topics" => $data

);


echo json_encode($myData);
?>


SQL:


SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `test` -- ---------------------------- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `title` varchar(50) DEFAULT NULL, `threadid` int(11) DEFAULT NULL, `username` varchar(50) DEFAULT NULL, `userid` int(11) DEFAULT NULL, `dateline` date DEFAULT NULL, `postid` int(11) DEFAULT NULL, `forumtitle` varchar(50) DEFAULT NULL, `forumid` int(11) DEFAULT NULL, `replycount` int(11) DEFAULT NULL, `lastpost` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=cp1251; -- ---------------------------- -- Records of test -- ---------------------------- INSERT INTO `test` VALUES ('23423', '234234', '23423', '4234', '0000-00-00', '4234', '234234', '234', '23423', '423423'); INSERT INTO `test` VALUES ('111', '22', '333', '444', '0000-00-00', '4444', '5555', '555', '55', '55'); INSERT INTO `test` VALUES (null, '6', '6', '6', null, '6', '6', '5', '6', null); INSERT INTO `test` VALUES (null, null, '5', '5', '0000-00-00', '5', null, null, null, null);