Skip to content

Commit

Permalink
Upgrade to release v3.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jul 14, 2015
1 parent 9359dcc commit 5e5229f
Show file tree
Hide file tree
Showing 40 changed files with 180 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015
* @package yii2-grid
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion BooleanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
6 changes: 6 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 3.0.6
=============
**Date:** 15-Jul-2015

1. (enh #338): Various enhancements for grid excel export formatting.

Version 3.0.5
=============
**Date:** 07-Jul-2015
Expand Down
2 changes: 1 addition & 1 deletion CheckboxColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion CheckboxColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
95 changes: 94 additions & 1 deletion ColumnTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down Expand Up @@ -147,6 +147,99 @@ protected function checkValidFilters()
}
}

/**
* Gets Default Excel Cell Format
*
* @return string
*/
public function getDefaultExcelFormat()
{
if (!isset($this->format)) {
return '';
}

}

/**
* Parses Excel Cell Formats for export
*
* @return string
*/
public function parseExcelFormats(&$options, $model, $key, $index)
{
$autoFormat = $this->grid->autoXlFormat;
if (!isset($this->xlsFormat) && !$autoFormat) {
return;
}
$fmt = '';
$format = is_array($this->format) ? $this->format[0] : $this->format;
$formatter = $this->grid->formatter;
if (isset($this->xlFormat)) {
$fmt = $this->xlFormat;
} elseif ($autoFormat && isset($this->format)) {
$tSep = isset($formatter->thousandSeparator) ? $formatter->thousandSeparator : ',';
$dSep = isset($formatter->decimalSeparator) ? $formatter->decimalSeparator : '.';
switch ($format) {
case 'text':
case 'html':
case 'raw':
case 'ntext':
case 'paragraphs':
case 'spellout':
case 'boolean':
case 'relativeTime':
$fmt = '\@';
break;
case 'integer':
$fmt = "\\#\\{$tSep}\\#\\#0";
break;
case 'decimal':
case 'percent':
case 'scientific':
$decimals = is_array($this->format) && isset($this->format[1]) ? $this->format[1] : 2;
$append = $decimals > 0 ? "\\{$dSep}" . str_repeat('0', $decimals) : '';
if ($format == 'percent') {
$append .= '%';
}
$fmt = ($format == 'scientific') ? "0{$append}E+00" : "\\#\\{$tSep}\\#\\#0" . $append;
break;
case 'currency':
$curr = is_array($this->format) && isset($this->format[1]) ? $this->format[1] :
isset($formatter->currencyCode) ? $formatter->currencyCode . ' ' : '';
$fmt = "{$curr}\\#\\{$tSep}\\#\\#0{$dSep}00";
break;
case 'date':
case 'time':
$fmt = 'Short ' . ucfirst($format);
break;
case 'datetime':
$fmt = 'yyyy\-MM\-dd HH\:mm\:ss';
break;
default:
$fmt = '';
break;
}
}
if ($format === 'date' || $format === 'datetime' || $format === 'time') {
$rawValue = $this->getDataCellValue($model, $key, $index);
switch ($format) {
case 'date':
$rawVal = $formatter->format($rawValue, ['date', 'php:Y-m-d']);
break;
case 'datetime':
$rawVal = $formatter->format($rawValue, ['date', 'php:Y-m-d H:i:s']);
break;
case 'time':
$rawVal = $formatter->format($rawValue, ['date', 'php:H:i:s']);
break;
}
$options['data-raw-value'] = $rawVal;
} elseif ($format === 'integer' || $format === 'decimal' || $format === 'percent' || $format === 'scientific') {
$options['data-raw-value'] = $this->getDataCellValue($model, $key, $index);
}
Html::addCssStyle($options, ['mso-number-format' => '"' . $fmt . '"']);
}

/**
* Checks `hidden` property and hides the column from display
*
Expand Down
9 changes: 8 additions & 1 deletion DataColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down Expand Up @@ -280,6 +280,12 @@ class DataColumn extends \yii\grid\DataColumn
* - `options`: array, HTML attributes for the group footer row.
*/
public $groupFooter = [];

/**
* @var string the cell format for EXCEL exported content.
* @see http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html
*/
public $xlFormat;

/**
* @var array of row data for the column for the current page
Expand Down Expand Up @@ -324,6 +330,7 @@ public function renderDataCell($model, $key, $index)
{
$options = $this->fetchContentOptions($model, $key, $index);
$this->parseGrouping($options, $model, $key, $index);
$this->parseExcelFormats($options, $model, $key, $index);
$this->initPjax($this->_clientScript);
return Html::tag('td', $this->renderDataCellContent($model, $key, $index), $options);
}
Expand Down
2 changes: 1 addition & 1 deletion EditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion ExpandRowColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion ExpandRowColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion FormulaColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion GridExportAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion GridFloatHeadAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion GridGroupAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion GridResizeColumnsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion GridResizeStoreAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
9 changes: 8 additions & 1 deletion GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down Expand Up @@ -611,6 +611,13 @@ class GridView extends \yii\grid\GridView
*/
public $exportConversions = [];

/**
* @var boolean, applicable for EXCEL export content only. This determines whether the exported EXCEL cell data
* will be automatically guessed and formatted based on `DataColumn::format` property. You can override this
* behavior and change the auto-derived format mask by setting `DataColumn::xlFormat`.
*/
public $autoXlFormat = false;

/**
* @var array|boolean the HTML attributes for the grid container. The grid table items
* will be wrapped in a `div` container with the configured HTML attributes. The ID for
Expand Down
2 changes: 1 addition & 1 deletion GridViewAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Refer [detailed documentation](http://demos.krajee.com/grid) and/or a [complete
![GridView Screenshot](https://lh4.googleusercontent.com/-4x-CdyyZAsY/VNxLPmaaAXI/AAAAAAAAAQ8/XYYxTiQZvJk/w868-h516-no/krajee-yii2-grid.jpg)

## Latest Release
The latest version of the module is v3.0.5. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details.
The latest version of the module is v3.0.6. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details.

New features with release 2.7.0.

Expand All @@ -33,6 +33,7 @@ New features with release 2.7.0.
5. Recursively replace/merge PDF export configuration correctly.
6. Include demo messages for auto generating via config.
7. Allows grouping grid column data, including master detail groups and generating group summaries (since v3.0.5).
8. Allows special formatting of data for cells exported in Excel Format.

> NOTE: This extension depends on other yii2 extensions based on the functionality chosen by you. It will not install such dependent packages by default, but will prompt through an exception, if accessed.
For example, if you choose to enable PDF export, then the [yii2-mpdf](http://demos.krajee.com/mpdf) will be mandatory and exception will be raised if `yii2-mpdf` is not installed.
Expand Down
2 changes: 1 addition & 1 deletion RadioColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
2 changes: 1 addition & 1 deletion RadioColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down
20 changes: 18 additions & 2 deletions SerialColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*/

namespace kartik\grid;
Expand Down Expand Up @@ -98,6 +98,20 @@ class SerialColumn extends \yii\grid\SerialColumn
*/
public $mergeHeader = true;

/**
* @var string|array in which format should the value of each data model be displayed as (e.g. `"raw"`, `"text"`, `"html"`,
* `['date', 'php:Y-m-d']`). Supported formats are determined by the [[GridView::formatter|formatter]] used by
* the [[GridView]]. Default format is "text" which will format the value as an HTML-encoded plain text when
* [[\yii\i18n\Formatter]] is used as the [[GridView::$formatter|formatter]] of the GridView.
*/
public $format = 'text';

/**
* @var string the cell format for EXCEL exported content.
* @see http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html
*/
public $xlFormat;

/**
* @var array of row data for the column for the current page
*/
Expand All @@ -120,6 +134,8 @@ public function init()
public function renderDataCell($model, $key, $index)
{
$options = $this->fetchContentOptions($model, $key, $index);
return Html::tag('td', $this->renderDataCellContent($model, $key, $index), $options);
$this->parseExcelFormats($options, $model, $key, $index);
$out = $this->grid->formatter->format($this->renderDataCellContent($model, $key, $index), $this->format);
return Html::tag('td', $out, $options);
}
}
2 changes: 1 addition & 1 deletion assets/css/kv-grid-expand.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 3.0.5
* @version 3.0.6
*
* Gridview ExpandRowColumn styling and enhancements
* Built for Yii Framework 2.0
Expand Down
Loading

0 comments on commit 5e5229f

Please sign in to comment.