nikolaposa/np-jq-grid

This package is abandoned and no longer maintained. No replacement package was suggested.

ZF2 Module which facilitates server-side integration of a JqGrid jQuery plugin

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 Module which facilitates server-side integration of a JqGrid JS library, one of the most popular jQuery plugins for displaying tabular data.

WARNING: This package is no longer maintained

Installation

You can install this module either by cloning this project into your ./vendor/ directory, or using composer, which is more recommended:

Add this project into your composer.json:

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

Tell composer to download NP_JqGrid by running update command:

$ php composer.phar update

For more information about composer itself, please refer to getcomposer.org.

Enable the module in your application.config.php:

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

Usage

Controller plugin

As communication with some grid is based on AJAX requests handled by some controller action, key component of this module is a controller plugin, registered under the jqGrid service name. It provides methods for retrieving parameters sent by some grid, but also method for sending data to a grid. Typical use-case might look like as follows:

// ...
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);
    }
}
// ...

Adapters

JqGrid provdes several data retrieval strategies. NP_JqGrid module abstracts data retrieval routines by introducing NP_JqGrid\Mvc\Controller\Plugin\JqGrid\Adapter\AdapterInterface, which can be used to create custom adapter implementations. Currently, there is only one Adapter implementation available - Json, which is used by default.

Parameters inflection

When requesting grid parameters ($this->jqGrid()->getParams()), by default, resulting data is in form of a plain array, with raw jqGrid parameters in it. Again, this module provides ability to have custom strategies for inflecting native jqGrid in some format of your choice, through the mechanism of Params inflectors. For example:

<?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;
    }
}

Register your custom inflector with the params inflectors plugin manager at some point:

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

... or set it directly:

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