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); // Define the table columns $cols = array(); $cols['ID'] = array('index' => 'Customer.id', 'width' => '30', 'align' => 'center'); if (isset($customers[0]['ContactsCustomer'])) $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'width' => '75', 'align' => 'left'); $cols['Name'] = array('index' => 'Customer.name', 'width' => '150', 'align' => 'left'); $cols['Last Name'] = array('index' => 'PrimaryContact.last_name', 'width' => '100', 'align' => 'left'); $cols['First Name'] = array('index' => 'PrimaryContact.first_name', 'width' => '100', 'align' => 'left'); $cols['Unit(s)'] = array('index' => 'Customer.units', 'width' => '80', 'align' => 'center'); $cols['Comment'] = array('index' => 'Customer.comment', 'width' => '300', 'align' => 'center'); // Some of the columns should not be sortable foreach (array('Unit(s)') AS $field) $cols[$field]['sortable'] = false; // Create the javascript code for jqGrid to create each table column $colModels = array(); foreach ($cols AS $col) { $col['name'] = $col['index']; $colModels[] = '{ ' . implode(", ", array_map(create_function ('$k, $v', 'return "$k:".($v===false?"false":"\'$v\'");'), array_keys($col), array_values($col))) . '}'; } // Save just the column indices (fields) $colFields= array_map(create_function('$col', 'return $col["index"];'), $cols); // 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' => 'customers', 'action' => 'jqGridData', 'debug' => 0, )); // 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. ?>