From 9a3f2a93aef1cd1914883a7d32d1da8ed4251ce2 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Fri, 26 Dec 2014 19:36:57 +0530 Subject: [PATCH] Fix #22: Add property `enableFormatter` to enable/disable yii grid formatter --- CHANGE.md | 1 + ExportMenu.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGE.md b/CHANGE.md index 3de36ec..7451b6f 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -10,6 +10,7 @@ version 1.1.0 - (bug #16): Prevent default on menu item click when showConfirmAlert is set to false. - (bug #19): Correct rendering of menu when format config is disabled. - (bug #21): Set correct reference to `ActiveDataProvider` and `ActiveQueryInterface`. +- (enh #22): Add property `enableFormatter` to enable/disable yii grid formatter. version 1.0.0 ============= diff --git a/ExportMenu.php b/ExportMenu.php index 22c15f5..73ab3da 100644 --- a/ExportMenu.php +++ b/ExportMenu.php @@ -64,6 +64,14 @@ class ExportMenu extends GridView */ public $showConfirmAlert = true; + /** + * @var bool whether to enable the yii gridview formatter component. + * Defaults to `true`. If set to `false`, this will render content + * as `raw` format. + */ + public $enableFormatter = true; + + /** * @var bool whether to render the export menu as bootstrap button dropdown * widget. Defaults to `true`. If set to `false`, this will generate a simple @@ -711,8 +719,9 @@ public function generateRow($model, $key, $index) } elseif ($column instanceof \yii\grid\ActionColumn) { $value = ''; } else { + $format = $this->enableFormatter ? $column->format : 'raw'; $value = ($column->content === null) ? - $this->formatter->format($column->getDataCellValue($model, $key, $index), $column->format) : + $this->formatter->format($column->getDataCellValue($model, $key, $index), $format) : call_user_func($column->content, $model, $key, $index, $column); } if (empty($value) && !empty($column->attribute) && $column->attribute !== null) {