nikolaposa/np-jq-grid

此包已被弃用且不再维护。没有建议的替代包。

一个ZF2模块,用于实现JqGrid jQuery插件的服务器端集成

1.0.3 2015-09-04 10:39 UTC

This package is auto-updated.

Last update: 2019-08-06 11:11:54 UTC


README

Build Status

一个ZF2模块,用于实现JqGrid JS库的服务器端集成,JqGrid是最受欢迎的jQuery插件之一,用于显示表格数据。

警告:此包不再维护

安装

您可以通过将此项目克隆到您的 ./vendor/ 目录中,或使用更推荐的composer来安装此模块

将此项目添加到您的composer.json中

"require": {
    "nikolaposa/np-jq-grid": "1.*"
}

通过运行更新命令告诉composer下载NP_JqGrid

$ php composer.phar update

有关composer本身的更多信息,请参阅 getcomposer.org.

在您的 application.config.php 中启用模块

<?php
return array(
    'modules' => array(
        // ...
        'NP_JqGrid',
    ),
    // ...
);

使用方法

控制器插件

由于与某些网格的通信基于由某些控制器动作处理的AJAX请求,此模块的关键组件是注册在 jqGrid 服务名下的 控制器插件。它提供检索某些网格发送的参数的方法,同时也提供向网格发送数据的方法。一个典型的用例可能如下所示

// ...
public function listAction()
{
    if ($this->request->isXmlHttpRequest()) {
        $gridParams = $this->jqGrid()->getParams(); //Get query data from a grid
        $data = someDataRetrievalMethod($gridParams);

        return $this->jqGrid()->buildModel($data); //Send data to a grid
    } else {
        $this->sendError(400);
    }
}
// ...

适配器

JqGrid提供了几种 数据检索策略。NP_JqGrid模块通过引入 NP_JqGrid\Mvc\Controller\Plugin\JqGrid\Adapter\AdapterInterface 抽象数据检索例程,该接口可用于创建自定义适配器实现。目前只有一个适配器实现可用 - Json,默认使用。

参数折叠

当请求网格参数($this->jqGrid()->getParams())时,默认情况下,结果数据为纯数组形式,其中包含原始jqGrid参数。同样,此模块提供自定义策略来折叠原生jqGrid,使其符合您选择的格式,通过Params inflectors机制实现。例如

<?php
namespace My\Mvc\Controller\Plugin\JqGrid\ParamsInflector;

use NP_JqGrid\Mvc\Controller\Plugin\JqGrid\ParamsInflector\InflectorInterface;

class Custom implements InflectorInterface
{
    public function inflect(array $params)
    {
        //your custom implementation goes here
        return $params;
    }
}

在某个位置将您的自定义inflector注册到params inflectors插件管理器中

// ...
$this->jqGrid()->getParamsInflectorPluginManager()->setInvokableClass('custom', 'My\Mvc\Controller\Plugin\JqGrid\ParamsInflector\Custom');
$this->jqGrid()->setParamsInflector('custom');
// ...

... 或者直接设置它

// ...
$this->jqGrid()->setParamsInflector($myInflectorInstance);
// ...