【问题标题】:Ext Js Paging not works with ExtDirect Grid PanelExt Js 分页不适用于 ExtDirect 网格面板
【发布时间】:2014-02-24 10:54:01
【问题描述】:

这是我的线程,我在这个区域发布了实际的分页问题。 你可以从这个线程中帮助我 煎茶论坛 sencha forum Ext Paging problem with EXt direct Grid panel

【问题讨论】:

  • 你有你的服务器端代码来处理分页吗?当您单击下一步时,将使用 start 和 limit 参数调用网格存储,您需要使用该值从服务器返回结果
  • 是的,当我应用它时,我得到了开始和限制,我在第一次加载时只得到 5 个值。下一页被禁用
  • 您还需要获取totalProperty,即要用于分页的记录总数。您返回的结果应该包含总记录数,例如 47 条,并且需要映射到代理读取器 totalProperty。如果您需要示例,请告诉我
  • 我添加了一个简单的例子作为答案
  • 但我的代理有点不同,我使用类型:'direct',我通过 directFn 调用

标签: extjs4 gridpanel ext-direct


【解决方案1】:

终于得到了论坛的答案

我的商店 Js

var store = Ext.create('Ext.data.Store', {
        model : 'Users',
        remoteSort : true,
        autoLoad : true,
        pageSize: 5, // items per page

        sorters : [{
            property : 'name',
            direction : 'ASC'
        }],

        proxy : {
            type : 'direct',
            directFn : 'Users.showAllUsers',
            reader: {

                    root: 'users'

            }

        }
});

我的 PHP 函数

function showAllUsers($params)
{
    $sort = $params->sort[0];
    $field = $sort->property;
    $direction = $sort->direction;
    $start = $params->start;
    $end = $params->limit;

    ($direction == 'ASC' ? 'ASC' : 'DESC');

    $dbh = Dbconfig::dbconnect();

    $stmt = $dbh->prepare("SELECT count(*) FROM users");
    $stmt->execute();
    $number_of_rows = $stmt->fetchColumn(); 

    $sth = $dbh->prepare("SELECT * FROM users ORDER BY name $direction LIMIT $start,$end");
    $sth->execute();
    $dataAll = $sth->fetchAll();


    $data = array(
            "success" => mysql_errno() == 0,
            "total" => $number_of_rows,
            "users" => $dataAll
    );

    return $data;
}

【讨论】:

    【解决方案2】:

    以下是关于您的商店和示例结果的示例,以便您的分页按要求工作。

    商店应该如下所示

    var myStore = Ext.create('Ext.data.Store', {
     fields: [
         {name: 'firstName', type: 'string'},
         {name: 'lastName',  type: 'string'}
     ],
     proxy: {
         type: 'ajax',
         url: '/users.json',
         reader: {
            type: 'json',
            root: 'records',
            totalProperty:  'recordCount',
            successProperty: 'success'
         }
     }
    });
    

    你的服务器的结果应该是这样的

    {
      recordCount: 63,
      records: [
      {
        id: 944,
        firstName: "Shannon",
        lastName: "Joy"
      },
      {
         id: 1819,
         firstName: "Remi"
         lastName: "Lucas"
      },
      .......
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多