ZendX_JQuery + jqGrid

    Continuing the theme of the Zend / Doctrine bundle.
    Given that it will be necessary to resolve the issue of paging data from a table by page, it was decided to use jqGrid as this tool.
    The reason for choosing is simple - at the moment it is one of the most powerful grids, with good documentation and so on.

    1) Create a View_Helper. In our example, we create this class in our library - Xms_ZendX_JQuery_View_Helper_jqGrid

    public function jqGrid($id, array $params = array())

    {

        $params = $this -> _adjuctParams($params);

        if(count($params) > 0) {

            $encodedParams = ZendX_JQuery::encodeJson($params);

        } else {

            $encodedParams = "{}";

    }

     

        $js = sprintf('%s("#%s").jqGrid(%s);',

                     ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),

                     $id,

                     $encodedParams

                     );

        $this->jquery->addOnLoad($js);

        $this-> view -> headscript()->appendFile('/js/jquery/jquery.jqGrid.js');

        $this-> view -> headLink()-> appendStylesheet('/css/jsgrid/steel/grid.css');

     

        $html = "";

        $html .= '
    ';

        return $html;

    }


    What happens in this method
    1) The parameters for installing jqGrid are reduced to the full form needed to display the grid.
    2) A script and a style file are added
    3) Tags are written to display the grid itself and pagination.
    4) The onLoad event is added to initialize the grid on the client.

    Now register the helper in bootstrap
    $ view-> addHelperPath ('Xms / ZendX / JQuery / View / Helper /', 'Xms_ZendX_JQuery_View_Helper');

    And in our view script, we call the helper to get the
    jqGrid grid ("jqGrid", $ this-> jqGridParams); ?>

    Where is jqGridParams created in the controller as follows
    $columns = Xms_DoctrineX_Table::getAccessibleColumns('Modules');

    foreach($columns as $key=>$val){

        $colNames[] = $this->_translate->_($key);

        $colModel[] = array("name" => $key, "sortable" => "true", "align"=> "right");

    }

    $this->view->jqGridParams = array('url'=>'/cms/modules/index',

                                    'colNames'=>$colNames,

                                    'colModel'=>$colModel,

                                    );



    A set of columns is created dynamically and passed as a parameter to the view script. This is done so that the grid can display those fields that the user has access to, since the sets of available fields are constantly changing.

    That's all sobsno. The result is a dynamic grid, with a varying set of fields depending on the rights.

    Also popular now: