【问题标题】:Paging in Ext Grid外部网格中的分页
【发布时间】:2015-04-16 19:22:56
【问题描述】:

您好,我使用的是 Ext Js 版本 4.1.8,我想在我的 extjs 网格上添加分页。

我一直在用

Ext.create('Ext.data.Store', {
    model: 'List',    
    proxy:{
       type: 'ajax',
       api:{
           read:'getJson.php',
       },
       extraParams:{
           PRKEY : selectedProjId
       },
    },
    reader:{
       type: 'json',
       root: 'data',    
    }
});

这很好,但是如果我在我的 php 文件中更改我的 json 格式并将根类型更改为其他字符串,例如“用户”,我看不到任何数据

这是我在getJson.php中创建json的代码

//in a loop
$aNode = array( 
    "Name" => "My Name",
    "ID"   => "123");
array_push($nodeArr, $aNode);
//end of loop

$json = new Services_JSON;
echo $json->encode($nodeArr);

这是我要运行的 php 代码

//in a loop
$aNode = array( 
"Name" => "My Name",
    "ID"   => "123");
array_push($nodeArr, $aNode);
//end of loop

$json = new Services_JSON;
$jsonResult = array(
    'success' => "true",
    'users' => $nodeArr
);
echo $json->encode($jsonResult );

这是新的商店代码

Ext.create('Ext.data.Store', {
    model: 'List',  
    proxy:{
        type: 'ajax',
        api:{
            read:'getJson.php',
        },
        extraParams:{
            PRKEY :selectedProjId
        },
    },
    reader:{
        type: 'json',
        root: 'users'
    }
});

请帮忙,以便我可以在商店的阅读器中添加 totalProperty 并执行分页。

【问题讨论】:

  • 您是否将商店定义更改为reader: { type:'json', root: 'users' }
  • 是的,那是旧的商店样本正在工作,我将粘贴新的等待
  • @Fahrad 你有root: 'tasks' 在存储中,你正在发送带有密钥'users' 的数组,这就是你没有数据的原因
  • @szapio 我很抱歉这是我的问题中的一个错字我在我的代码中使用“用户”
  • 现在有了这些更改,它应该可以工作了。你让它工作了吗?

标签: javascript php json extjs pagination


【解决方案1】:

啊,伙计们。 我在代理块之外使用“阅读器”。我对其进行了更改并将其添加到代理中,并且可以正常工作。

干杯!这是它的工作原理

Ext.create('Ext.data.Store', {
    model: 'List',  
    proxy:{
        type: 'ajax',
        api:{
            read:'getJson.php',
        },
        extraParams:{
            PRKEY :selectedProjId
        },
        reader:{
            type: 'json',
            root: 'users'
        }
    }        
});

【讨论】:

    【解决方案2】:

    在success旁边加上totalProperty的值,例如:

    $total = get_total_number_of_records();
    $jsonResult = array(
        'success' => "true",
        'total' => $total
        'users' => $nodeArr
    );
    

    除了total之外,服务器端必须遵守发送的startlimit参数,并且它必须只返回limitstart开始的记录数,而不是全部来自数据库。

    【讨论】:

    • “没有成功”到底是什么意思?发生了什么事出乎你的意料?错误信息?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-27
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多