diff --git a/README.md b/README.md
index 052a0fc..368d0da 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
Easy tabular data for CakePHP (cakephp.org)
-- by Robert Ross (rross@sdreader.com)
-- available at http://github.com/rross0227
- -- requires CakePHP 1.3.x
+ -- requires CakePHP 2.x
Copyright (c) 2011 The Daily Save, LLC. All rights reserved.
@@ -47,7 +47,7 @@ In your view file you can now create grids easily by doing something like this:
$this->Grid->addAction('Edit', array('controller' => 'orders', 'action' => 'edit'), array('/Order/id'));
- echo $this->Grid->generate($results);
+ echo $this->Grid->generate($orders);
This will create a 4 column grid (including actions) for all of your orders or whatever you like!
CakeGrid uses the Set::extract format found here: http://book.cakephp.org/view/1501/extract
@@ -133,6 +133,13 @@ This will output in the cell the users first and last name together. Concat uses
'/User/register_ip'
));
+## Paginate
+By setting paginate as true you instruct CakeGrid to use the Paginator::sort method to create the headers of your table
+
+ $this->Grid->addColumn('User', '/User/name', array('paginate'=>true));
+
+CakeGrid won't add pagination links at the end of the table, you should add them yourself if you need them.
+
## Elements
CakeGrid allows the usage of your own elements to be used in cells. This is useful if you're wanting to use a hasMany relationship into a dropdown or something similar.
diff --git a/views/elements/csv/column_actions.ctp b/View/Elements/csv/column_actions.ctp
similarity index 100%
rename from views/elements/csv/column_actions.ctp
rename to View/Elements/csv/column_actions.ctp
diff --git a/views/elements/csv/grid_empty_row.ctp b/View/Elements/csv/grid_empty_row.ctp
similarity index 100%
rename from views/elements/csv/grid_empty_row.ctp
rename to View/Elements/csv/grid_empty_row.ctp
diff --git a/views/elements/csv/grid_full.ctp b/View/Elements/csv/grid_full.ctp
similarity index 100%
rename from views/elements/csv/grid_full.ctp
rename to View/Elements/csv/grid_full.ctp
diff --git a/views/elements/csv/grid_headers.ctp b/View/Elements/csv/grid_headers.ctp
similarity index 100%
rename from views/elements/csv/grid_headers.ctp
rename to View/Elements/csv/grid_headers.ctp
diff --git a/views/elements/csv/grid_row.ctp b/View/Elements/csv/grid_row.ctp
similarity index 100%
rename from views/elements/csv/grid_row.ctp
rename to View/Elements/csv/grid_row.ctp
diff --git a/views/elements/table/column_actions.ctp b/View/Elements/table/column_actions.ctp
similarity index 100%
rename from views/elements/table/column_actions.ctp
rename to View/Elements/table/column_actions.ctp
diff --git a/views/elements/table/grid_empty_row.ctp b/View/Elements/table/grid_empty_row.ctp
similarity index 100%
rename from views/elements/table/grid_empty_row.ctp
rename to View/Elements/table/grid_empty_row.ctp
diff --git a/views/elements/table/grid_full.ctp b/View/Elements/table/grid_full.ctp
similarity index 100%
rename from views/elements/table/grid_full.ctp
rename to View/Elements/table/grid_full.ctp
diff --git a/View/Elements/table/grid_headers.ctp b/View/Elements/table/grid_headers.ctp
new file mode 100644
index 0000000..cc6aa26
--- /dev/null
+++ b/View/Elements/table/grid_headers.ctp
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/views/elements/table/grid_row.ctp b/View/Elements/table/grid_row.ctp
similarity index 100%
rename from views/elements/table/grid_row.ctp
rename to View/Elements/table/grid_row.ctp
diff --git a/views/helpers/grid.php b/View/Helper/GridHelper.php
similarity index 88%
rename from views/helpers/grid.php
rename to View/Helper/GridHelper.php
index 2a997c7..cd4aae2 100644
--- a/views/helpers/grid.php
+++ b/View/Helper/GridHelper.php
@@ -2,7 +2,7 @@
class GridHelper extends AppHelper {
public $name = 'Grid';
- public $plugin_name = 'cake_grid';
+ public $plugin_name = 'CakeGrid';
/**
* Load html helper for links and such
@@ -53,7 +53,8 @@ class GridHelper extends AppHelper {
*
* @author Robert Ross
*/
- function __construct(){
+ function __construct(View $View, $settings = array()){
+ parent::__construct( $View,$settings);
$this->options(array());
}
@@ -108,7 +109,8 @@ function addColumn($title, $valuePath, array $options = array()){
'type' => 'string',
'element' => false,
'linkable' => false,
- 'total' => false
+ 'total' => false,
+ 'paginate' => false
);
$options = array_merge($defaults, $options);
@@ -159,8 +161,8 @@ function addAction($name, array $url, array $trailingParams = array(), array $op
* @author Robert Ross
*/
function generate($results){
- $View = $this->__view();
-
+ $View = $this->_View;
+
$directory = $this->__settings['type'];
if($this->__settings['type'] == 'csv' && !empty($this->__totals)){
@@ -178,17 +180,21 @@ function generate($results){
'plugin' => $this->plugin_name,
'headers' => $this->__columns,
'options' => $this->__settings
- ));
- $results = $this->results($results);
-
+ ),
+ array( 'plugin' => $this->plugin_name)
+ );
+
+ $results = $this->results($results);
$generated = $View->element($this->elemDir . DS . 'grid_full', array(
- 'plugin' => $this->plugin_name,
+ // 'plugin' => $this->plugin_name,
'headers' => $headers,
'results' => $results,
'options' => $this->__settings
- ));
-
- return $generated;
+ ),
+ array( 'plugin' => $this->plugin_name)
+ );
+
+ return $generated;
}
/**
@@ -200,7 +206,7 @@ function generate($results){
*/
function results($results = array()){
$rows = array();
- $View = $this->__view();
+ $View = $this->_View;
foreach($results as $key => $result){
//-- Loop through columns
@@ -215,7 +221,9 @@ function results($results = array()){
'zebra' => $key % 2 == 0 ? 'odd' : 'even',
'rowColumns' => $rowColumns,
'options' => $this->__settings
- ));
+ ),
+ array( 'plugin' => $this->plugin_name)
+ );
}
if(!empty($this->__totals)){
@@ -238,7 +246,7 @@ function results($results = array()){
}
if($this->__settings['type'] == 'csv'){
- $total = intval(str_replace(array('$', ','), '', $total));
+ $total = floatval(str_replace(array('$', ','), '', $total));
$totalColumns[] = $total;
continue;
}
@@ -255,7 +263,9 @@ function results($results = array()){
'rowColumns' => $totalColumns,
'options' => $this->__settings,
'zebra' => 'totals'
- ));
+ ),
+ array( 'plugin' => $this->plugin_name)
+ );
}
//-- Upon review, this if statement is hilarious
@@ -264,9 +274,10 @@ function results($results = array()){
'plugin' => $this->plugin_name,
'colspan' => sizeof($this->__columns) + (sizeof($this->__actions) ? 1 : 0),
'options' => $this->__settings
- ));
+ ),
+ array( 'plugin' => $this->plugin_name));
}
-
+
return implode("\n", $rows);
}
@@ -322,9 +333,9 @@ private function __generateColumn($result, $column){
}
if(isset($column['options']['element']) && $column['options']['element'] != false){
- $View = $this->__view();
+ $View = $this->_View;
- return $View->element($this->elemDir . DS . $column['options']['element'], array('result' => $value));
+ return $View->element($this->elemDir . DS . $column['options']['element'], array('result' => $value));
} else {
if(isset($column['options']['type']) && $column['options']['type'] == 'date'){
$value = date('m/d/Y', strtotime($value));
@@ -333,7 +344,7 @@ private function __generateColumn($result, $column){
} else if(isset($column['options']['type']) && $column['options']['type'] == 'money' && $this->__settings['type'] != 'csv'){
$value = money_format('%n', $value);
} else if(isset($column['options']['type']) && $column['options']['type'] == 'actions'){
- $View = $this->__view();
+ $View = $this->_View;
$actions = array();
//-- Need to retrieve the results of the trailing params
@@ -352,12 +363,12 @@ private function __generateColumn($result, $column){
}
$actions[$name] = array(
- 'url' => Router::url($action['url'] + $trailingParams),
+ 'url' => $action['url'] + $trailingParams,
'options' => $action['options']
);
}
- return $View->element($this->elemDir . DS . 'column_actions', array('plugin' => $this->plugin_name, 'actions' => $actions), array('Html'));
+ return $View->element($this->elemDir . DS . 'column_actions', array( 'actions' => $actions), array('plugin' => $this->plugin_name));
}
}
@@ -423,13 +434,13 @@ function csvData($data){
* @return void
* @author Robert Ross
*/
- private function __view() {
- if (!empty($this->globalParams['viewInstance'])) {
- $View = $this->globalParams['viewInstance'];
- } else {
- $View = ClassRegistry::getObject('view');
- }
-
- return $View;
- }
+// private function __view() {
+// if (!empty($this->globalParams['viewInstance'])) {
+// $View = $this->globalParams['viewInstance'];
+// } else {
+// $View = ClassRegistry::getObject('view');
+// }
+//
+// return $View;
+// }
}
\ No newline at end of file
diff --git a/views/elements/table/grid_headers.ctp b/views/elements/table/grid_headers.ctp
deleted file mode 100644
index 3e8a3fb..0000000
--- a/views/elements/table/grid_headers.ctp
+++ /dev/null
@@ -1,5 +0,0 @@
-
\ No newline at end of file
diff --git a/webroot/css/cakegrid.css b/webroot/css/cakegrid.css
new file mode 100644
index 0000000..3f5fa10
--- /dev/null
+++ b/webroot/css/cakegrid.css
@@ -0,0 +1,183 @@
+.DataGrid{
+ clear: both;
+ display: block;
+
+
+}
+
+.RTL {
+ direction: rtl;
+}
+
+
+.DataGrid div.Caption{
+ display: block;
+ background:url("/CakeGrid/img/captionbg.gif") repeat-x scroll center top transparent;
+ font-weight:bold;
+ overflow:hidden;
+
+ white-space:nowrap;
+ //padding: 5px 10px;
+ border-left:1px solid #CCCCCC;
+ border-right:1px solid #CCCCCC;
+
+}
+
+.DataGrid div.ButtomsGroup{
+ background:url("/CakeGrid/img/captionbg.gif") repeat-x scroll center top #FAFAFA;
+ border-top: 1px solid #ccc;
+ border-bottom: 1px solid #fff;
+ border-left:1px solid #CCCCCC;
+ border-right:1px solid #CCCCCC;
+ overflow: hidden;
+ padding: 3px 3px;
+
+}
+
+
+.DataGrid div.ButtomsGroup a.buttom{
+ display: inline-block;
+ vertical-align: top;
+ padding: 5px 30px 5px 10px;
+ border: 1px solid transparent;
+ margin: 0px 2px;
+ cursor: pointer;
+ font-family: tahoma;
+ font-size: 12px;
+ text-shadow:0 1px 0 #ccc;
+ color: #333;
+ background-repeat: no-repeat;
+ background-position: 90% center;
+
+
+}
+
+.DataGrid div.ButtomsGroup .icon-add{
+ background-image: url("/irsa/img/icons/add.png") ;
+}
+
+.DataGrid div.ButtomsGroup a.buttom:hover{
+
+ border-right: 1px solid #fff;
+ border-top: 1px solid #fff;
+ border-left: 1px solid #eee;
+ outline: 1px solid #ccc;
+
+}
+
+
+.DataGrid div.ButtomsGroup div.Spliter{
+ border-left:1px solid #CCCCCC;
+ border-right:1px solid #FFFFFF;
+ height:22px;
+ margin:1px;
+ display: inline-block;
+}
+
+.DataGrid div.ButtomsGroup div.RTL{
+ float: right;
+}
+
+
+.DataGrid .GridScroller {
+ overflow:auto ;
+ border: none;
+
+}
+
+.DataGrid table{
+ border-collapse: separate;
+ table-layout: fixed;
+ border-spacing: 1px 1px;
+ border-left:1px solid #CCCCCC;
+ border-top:1px solid #c7c7c7;
+
+}
+
+.DataGrid table thead tr.cg_header {
+ background: -moz-linear-gradient(center top , #EFEFEF, #CACACA) repeat scroll 0 0 transparent;
+
+
+}
+
+
+ .DataGrid table thead tr.cg_header th , .DataGrid table tbody tr td{
+ padding: 5px 5px;
+ border-right:1px solid #CCCCCC;
+ border-left:1px solid #fff;
+ vertical-align: middle;
+ white-space: nowrap;
+
+ }
+
+ .DataGrid table tbody tr.cg_row td{
+ padding: 8px 5px;
+ }
+
+ .DataGrid table thead tr.tableHeader th {
+ padding: 8px 5px;
+
+ }
+
+ .DataGrid table thead tr.tableHeader th div.Col{
+ height: 22px;
+ line-height: 22px;
+ padding-right: 30px;
+ min-width: 100px;
+ }
+
+ .DataGrid table thead tr.tableHeader th div.RowNumber{
+ height: 22px;
+ line-height: 22px;
+ }
+
+.DataGrid table thead tr.tableHeader th span.Scroller{
+ cursor: e-resize;
+ width: 2px;
+ height: 22px;
+ float: right;
+
+ }
+
+ .DataGrid table thead tr.tableHeader th span.RTL{
+ float: left;
+ }
+
+.DataGrid table thead tr.tableHeader th div.Sorter{
+ cursor: pointer;
+ float: left;
+ height: 16px;
+ width: 16px;
+ margin: 2px 5px ;
+ border:1px solid transparent;
+ }
+.DataGrid table thead tr.tableHeader th div.Sorter:hover{
+ border:1px solid #fff;
+ outline: 1px solid #ddd;
+}
+ .DataGrid table thead tr.tableHeader th div.RTL{
+ float: right;
+ margin: 2px 5px 0px 0px;
+ }
+
+
+ .DataGrid table tbody tr.cg_row.odd td{
+ background: #f7f7f7;
+ border-bottom: 1px solid #f7f7f7;
+
+ }
+
+
+ .DataGrid div.Footer{
+
+ border: none;
+ background:url("/irsa/img/wbg.gif") repeat-x scroll center top transparent;
+ font-weight:bold;
+ overflow:hidden;
+ white-space:nowrap;
+ border-bottom:1px solid #CCCCCC;
+ border-left:1px solid #CCCCCC;
+ border-right:1px solid #CCCCCC;
+ padding: 5px;
+ height: 10px;
+ }
\ No newline at end of file
diff --git a/webroot/img/bg.gif b/webroot/img/bg.gif
new file mode 100644
index 0000000..9ab78a2
Binary files /dev/null and b/webroot/img/bg.gif differ
diff --git a/webroot/img/captionbg.gif b/webroot/img/captionbg.gif
new file mode 100644
index 0000000..8046089
Binary files /dev/null and b/webroot/img/captionbg.gif differ