'.$this->pageTitle.''; if (!isset($limit)) $limit = 20; if (!isset($limitOptions)) { $limitOptions = array(); if ($limit < 10) array_push($limitOptions, 2, 5); if ($limit < 30) array_push($limitOptions, 10, 25); if ($limit > 10) array_push($limitOptions, 50, 200); if ($limit > 20) array_push($limitOptions, 500); } if (!isset($height)) $height = 'auto'; if (!isset($controller)) $controller = $this->params['controller']; if (!isset($grid_div_class)) $grid_div_class = ''; $grid_div_class = 'item grid list' . ($grid_div_class ? ' '.$grid_div_class : ''); if (!isset($grid_div_id)) $grid_div_id = $controller . '-list'; if (!isset($grid_id)) $grid_id = $grid_div_id . '-jqGrid'; if (!isset($search_fields)) $search_fields = array(); // Do some prework to bring in the appropriate libraries $imgpath = '/pmgr/site/css/jqGrid/basic/images'; $html->css('jqGrid/basic/grid', null, null, false); $html->css('jqGrid/jqModal', null, null, false); $javascript->link('jqGrid/jquery.jqGrid.js', false); $javascript->link('jqGrid/js/jqModal', false); $javascript->link('jqGrid/js/jqDnR', false); $javascript->link('pmgr_jqGrid', false); // Define the URL to fetch data from. // To prevent having to keep the controller and the view // in sync on which fields need to be queried by the // controller in order to be accessible to the view, // we'll just pass the desired fields to the controller // as part of the data fetch. $url = $html->url(array('controller' => $controller, 'action' => 'jqGridData', 'debug' => 0, )); // Create extra parameters that jqGrid will pass to our // controller whenever data is requested. // 'fields' will allow the controller to return only the // requested fields, and in the right order. Since fields // is a complex structure (an array), we'll need to // serialize it first for transport over HTTP. $postData = array(); $postData['fields'] = serialize(array_map(create_function('$col', 'return $col["index"];'), array_values($jqGridColumns))); // Determine if we're to be using a custom list, or if // the data will simply be action based. if (isset($custom_ids)) { $action = 'idlist'; $postData['idlist'] = serialize($custom_ids); } elseif (!isset($action)) { $action = null; } // 'action' will ensure that the controller provides the // correct subset of data $postData['action'] = $action; // Perform column customizations. // This will largely be based off of the 'formatter' parameter, // but could be on any pertinent condition. foreach ($jqGridColumns AS &$col) { $default = array(); // Make sure every column has a name $default['name'] = preg_replace("/\./", '-', $col['index']); // Perform customization based on formatter if (isset($col['formatter'])) { if ($col['formatter'] === 'id') { // Switch currency over to our own custom formatting $col['formatter'] = array('--special' => 'idFormatter'); $default['width'] = 50; $default['align'] = 'center'; } elseif ($col['formatter'] === 'currency') { // Switch currency over to our own custom formatting $col['formatter'] = array('--special' => 'currencyFormatter'); $default['width'] = 80; $default['align'] = 'right'; } elseif ($col['formatter'] === 'date') { $default['formatoptions'] = array('newformat' => 'm/d/Y'); $default['width'] = 90; $default['align'] = 'center'; } elseif ($col['formatter'] === 'name' || $col['formatter'] === 'longname') { $default['width'] = 100; if ($col['formatter'] === 'longname') $default['width'] *= 1.5; // No special formatting for name unset($col['formatter']); } elseif ($col['formatter'] === 'comment') { $default['width'] = 300; $default['sortable'] = false; } } $col = array_merge($default, $col); } // OK, now that everything is in place, get out of PHP mode, // and add the javascript code (along with a touch of HTML) // to kick this thing off. ?>