繁体   English   中英

分页不起作用,Extjs网格

[英]Paging not working, Extjs grid

我用底部的工具栏制作了一个extjs网格来创建分页行为,但是它不起作用,我也不知道问题出在哪里,我已经用本地数据完成了,但是当我使用数据库时却没有工作时,它会一次显示所有数据。
这是代码:

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

Ext.onReady(function() {
var categoriesStore = Ext.create('Ext.data.JsonStore', {
    autoLoad: true,
    pageSize : 10,      
    proxy: {
           type: 'ajax',
           url: 'GridDataBase/categories.php',
           reader: {
               type: 'json',
               totalProperty: 'total',
               root: 'categories',
               idProperty: 'name'
           }            
    },
    fields : ['id','name']
});

var panelOfData = Ext.create('Ext.grid.GridPanel',{
    store : categoriesStore,
    columns : [ {
        id : 'id',
        header : "Id",
        width : 20,
        sortable : true,
        dataIndex : 'id'
    }, {
        id : 'name',
        header : "Category Name",
        width : 75,
        sortable : true,
        dataIndex : 'name'
    } ],
    //stripeRows : true,

        //paging bar on the bottom
    bbar: Ext.create('Ext.PagingToolbar', {
        store: categoriesStore,
        displayInfo: true,
        displayMsg: '{0} - {1} of {2}',
        emptyMsg: "No categories to display"
    }),
    autoExpandColumn : 'name',
    height : 350,
    width : 600,
    renderTo : 'grid-ex',
    title : 'Categories'
});

categoriesStore.loadPage(1);
console.log(categoriesStore.count()); // the log here shows 0
});


这是PHP文件:

function GetCategories() {
    $query = "SELECT id, name FROM categorie";  
    $categories = array("categories" => array());
    @mysql_connect("localhost","superuser","SS4") or die();
    mysql_select_db("dbz"); !mysql_error () or die();
    $result = mysql_query($query);

    $num = mysql_num_rows($result);
    $i = 0;

    while ($row = mysql_fetch_assoc($result)) {
        $categories["categories"][$i] = $row;
        $i++;
    }

    return json_encode($categories);
}
echo GetCategories();

Extjs代码还会发送一些其他参数,以实现对服务器启动,限制的分页,并且这些参数必须在查询中使用,以将记录发回至存储的页面大小限制。 服务器响应还应该发送回带有记录总数(将被分配给storeTotalProperty的记录)的属性,该属性将用于计算页面数。

    store.load({
        params:{
            start:0,
            limit: itemsPerPage
        }
    });

希望能帮助到你!!

您尚未在服务器端实现分页。 尝试这个:

function GetCategories($start, $limit) {
    $query = "SELECT id, name FROM categorie LIMIT $start, $limit";  
    $categories = array("categories" => array());
    @mysql_connect("localhost","superuser","SS4") or die();
    mysql_select_db("dbz"); !mysql_error () or die();
    $result = mysql_query($query);

    $num = mysql_num_rows($result);
    $i = 0;

    while ($row = mysql_fetch_assoc($result)) {
        $categories["categories"][$i] = $row;
        $i++;
    }

    return json_encode($categories);
}
$start = isset($_GET['start']) ? $_GET['start'] : 0;
$limit = isset($_GET['limit']) ? $_GET['limit'] : 0;

echo GetCategories($start, $limit);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM