Fixed a bug in which jqGrid would fetch data from the current controller, not the controller responsible for populating the data. Added the ability to fetch data based strictly off of an ID list, which is useful for lists that are embedded in other pages, where the list conditions are entirely foreign to the controller responsible for providing the data. To assist with this one jqGrid virtual function needed the model added as a parameter, so I added it to them all and modified the jqGrid functions in the existing derived controllers. Right now the elements (such as contacts.ctp, the only working one) receive a full list of data to populate themselves. I could have simply taken this and passed it directly to jqGrid, with no need for further server interaction. However, this could result in some very large lists, and although pagination will ensure the user is not overwhelmed, the connection or the browser could be. Unless we have a strong performance need, I'll keep it this way. In the meantime, I'll leave the underlying data available to each element, in case I have to switch over. When all is proven out, I can simplify all the queries such that the extra data is never requested in the first place.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@122 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -12,7 +12,18 @@ if (0) { // REVISIT<AP>: Need to figure out how to put this in play
|
||||
}
|
||||
$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment');
|
||||
|
||||
//pr($contacts);
|
||||
$jqGrid_options = array('jqGridColumns' => $cols,
|
||||
'controller' => 'contacts',
|
||||
'caption' => isset($caption) ? $caption : null);
|
||||
|
||||
echo $this->element('jqGrid',
|
||||
array('jqGridColumns' => $cols));
|
||||
if (isset($contacts)) {
|
||||
$jqGrid_options += array('custom_ids' =>
|
||||
array_map(create_function('$data',
|
||||
'return $data["id"];'),
|
||||
$contacts),
|
||||
'limit' => 5);
|
||||
}
|
||||
|
||||
//pr($jqGrid_options);
|
||||
echo $this->element('jqGrid', $jqGrid_options);
|
||||
|
||||
@@ -6,14 +6,26 @@ if (!isset($caption))
|
||||
if (!isset($limit))
|
||||
$limit = 20;
|
||||
|
||||
if (!isset($limitOptions))
|
||||
$limitOptions = array(10, 20, 50, 200);
|
||||
if (!isset($limitOptions)) {
|
||||
$limitOptions = array();
|
||||
if ($limit < 10)
|
||||
$limitOptions += array(2, 5);
|
||||
if ($limit < 30)
|
||||
$limitOptions += array(10, 25);
|
||||
if ($limit > 10)
|
||||
$limitOptions += array(50, 200);
|
||||
if ($limit > 20)
|
||||
$limitOptions += array(500);
|
||||
}
|
||||
|
||||
if (!isset($height))
|
||||
$height = 'auto';
|
||||
|
||||
if (!isset($controller))
|
||||
$controller = $this->params['controller'];
|
||||
|
||||
if (!isset($gridId))
|
||||
$gridId = $this->params['controller'] . '-jqGrid';
|
||||
$gridId = $controller . '-jqGrid';
|
||||
|
||||
// Do some prework to bring in the appropriate libraries
|
||||
$imgpath = '/pmgr/site/css/jqGrid/basic/images';
|
||||
@@ -30,22 +42,35 @@ $javascript->link('jqGrid/js/jqDnR', false);
|
||||
// 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('action' => 'jqGridData',
|
||||
$url = $html->url(array('controller' => $controller,
|
||||
'action' => 'jqGridData',
|
||||
'debug' => 0,
|
||||
));
|
||||
|
||||
// Create extra parameters that jqGrid will pass to our
|
||||
// controller whenever data is requested. 'action' will
|
||||
// ensure that the controller provides the correct subset
|
||||
// of data, and 'fields' will allow it to return only the
|
||||
// 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('action' => $action,
|
||||
'fields' => serialize(array_map(create_function('$col',
|
||||
'return $col["index"];'),
|
||||
$jqGridColumns)));
|
||||
$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.
|
||||
|
||||
Reference in New Issue
Block a user