Skip to content

Commit

Permalink
Fix #820: Ability to strip HTML tags for columns from export
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 9, 2018
1 parent c03ff96 commit 6d67d8e
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 54 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Change Log: `yii2-grid`

## Version 3.2.0

**Date:** _under development_
**Date:** 09-Sep-2018

- (enh #820): Ability to strip HTML tags for columns from export.
- (enh #819): Enhance grid export generation for PJAX grids (correct timestamp).
- (enh #818): Correct PDF Export Generation response.
- (enh #816): Fix typo in check if has `xlFormat`.
Expand Down
9 changes: 9 additions & 0 deletions src/ColumnTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ trait ColumnTrait
*/
public $hiddenFromExport;

/**
* @var boolean whether to strip HTML tags from the column during export. This can be useful for column data that
* is mainly a hyperlink or contains HTML markup that are not needed for display at export. Defaults to `false`.
*/
public $stripTagsFromExport = false;

/**
* @var boolean whether to force no wrapping on all table cells in the column
* @see http://www.w3schools.com/cssref/pr_text_white-space.asp
Expand Down Expand Up @@ -386,6 +392,9 @@ protected function checkValidFilters()
*/
protected function parseVisibility()
{
if ($this->stripTagsFromExport) {
Html::addCssClass($this->options, 'strip-tags-export');
}
if ($this->hidden === true) {
Html::addCssClass($this->filterOptions, 'kv-grid-hide');
Html::addCssClass($this->headerOptions, 'kv-grid-hide');
Expand Down
2 changes: 1 addition & 1 deletion src/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 - 2018
* @version 3.1.8
* @version 3.2.0
*
* Gridview ExpandRowColumn styling and enhancements
*
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/kv-grid-expand.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/assets/css/kv-grid.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 - 2018
* @version 3.1.8
* @version 3.2.0
*
* Yii2 Gridview widget styling and enhancements for Bootstrap.
*
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/kv-grid.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-checkbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Client actions for kartik\grid\CheckboxColumn
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-checkbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-editable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Client actions for yii2-grid EditableColumn
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-editable.min.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Client actions for yii2-grid EditableColumn
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-expand.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* jQuery methods library for yii2-grid expand row column
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-expand.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 16 additions & 22 deletions src/assets/js/kv-grid-export.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Grid Export Validation Module for Yii's Gridview. Supports export of
* grid data as CSV, HTML, or Excel.
Expand Down Expand Up @@ -114,8 +114,6 @@
constructor: GridExport,
getArray: function (expType) {
var self = this, $table = self.clean(expType), head = [], data = {};
/** @namespace self.config.colHeads */
/** @namespace self.config.slugColHeads */
if (self.config.colHeads !== undefined && self.config.colHeads.length > 0) {
head = self.config.colHeads;
} else {
Expand Down Expand Up @@ -229,7 +227,7 @@
safeRemove = function (selector) {
$table.find(selector + '.' + self.gridId).remove();
};

if ($container.hasClass('kv-grid-wrapper')) {
$tHead = $container.closest('.floatThead-wrapper').find('.kv-thead-float thead');
} else {
Expand Down Expand Up @@ -261,6 +259,10 @@
}
$table.find('.skip-export').remove();
$table.find('.skip-export-' + expType).remove();
$table.find('.strip-tags-export').each(function () {
var $el = $(this), rawText = $el.text();
$el.html(rawText);
});
var htmlContent = $table.html();
htmlContent = self.preProcess(htmlContent);
$table.html(htmlContent);
Expand Down Expand Up @@ -299,7 +301,6 @@
self.$form.submit();
},
exportHTML: function () {
/** @namespace self.config.cssFile */
var self = this, $table = self.clean('html'), cfg = self.config,
css = (self.config.cssFile && cfg.cssFile.length) ? '<link href="' + self.config.cssFile + '" rel="stylesheet">' : '',
html = templates.html.replace('{encoding}', self.encoding).replace('{css}', css).replace('{data}',
Expand All @@ -308,8 +309,6 @@
},
exportPDF: function () {
var self = this, $table = self.clean('pdf');
/** @namespace self.config.contentAfter */
/** @namespace self.config.contentBefore */
var before = isEmpty(self.config.contentBefore) ? '' : self.config.contentBefore,
after = isEmpty(self.config.contentAfter) ? '' : self.config.contentAfter,
css = self.config.css,
Expand All @@ -327,25 +326,21 @@
var tmpColDelim = String.fromCharCode(11), // vertical tab character
tmpRowDelim = String.fromCharCode(0); // null character
// actual delimiter characters for CSV format
/** @namespace self.config.rowDelimiter */
/** @namespace self.config.colDelimiter */
var colD = '"' + self.config.colDelimiter + '"', rowD = '"' + self.config.rowDelimiter + '"';
// grab text from table into CSV formatted string
var txt = '"' + $rows.map(function (i, row) {
var $row = $(row), $cols = $row.find(self.columns);
return $cols.map(function (j, col) {
var $col = $(col), text = $col.text().trim();
return text.replace(/"/g, '""'); // escape double quotes
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowD)
.split(tmpColDelim).join(colD) + '"';
var $row = $(row), $cols = $row.find(self.columns);
return $cols.map(function (j, col) {
var $col = $(col), text = $col.text().trim();
return text.replace(/"/g, '""'); // escape double quotes
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowD)
.split(tmpColDelim).join(colD) + '"';
self.download(expType, txt);
},
exportJSON: function () {
var self = this, out = self.getArray('json');
/** @namespace self.config.indentSpace */
/** @namespace self.config.jsonReplacer */
out = JSON.stringify(out, self.config.jsonReplacer, self.config.indentSpace);
self.download('json', out);
},
Expand All @@ -355,11 +350,10 @@
$table.find('td[data-raw-value]').each(function () {
$td = $(this);
if ($td.css('mso-number-format') || $td.css('mso-number-format') === 0 || $td.css(
'mso-number-format') === '0') {
'mso-number-format') === '0') {
$td.html($td.attr('data-raw-value')).removeAttr('data-raw-value');
}
});
/** @namespace self.config.worksheet */
xls = templates.excel.replace('{encoding}', self.encoding).replace('{css}', css).replace('{worksheet}',
self.config.worksheet).replace('{data}', $('<div />').html($table).html()).replace(/"/g, '\'');
self.download('xls', xls);
Expand Down
7 changes: 4 additions & 3 deletions src/assets/js/kv-grid-export.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-group.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Grid grouping jquery library created for yii2-grid.
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-group.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-radio.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Client actions for yii2-grid RadioColumn
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-radio.min.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* Client actions for yii2-grid RadioColumn
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-toggle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* jQuery methods library for yii2-grid toggle data
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-grid-toggle.min.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.8
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.2.0
*
* jQuery methods library for yii2-grid toggle data
*
Expand Down

0 comments on commit 6d67d8e

Please sign in to comment.