Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripHTML to remove any HTML wrappers on the data prior to cell data being set #168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion js/core/core.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,13 @@ function _fnGetRowElements( settings, row, colIdx, d )
var cellProcess = function ( cell ) {
if ( colIdx === undefined || colIdx === i ) {
col = columns[i];
contents = $.trim(cell.innerHTML);
//if specified, ignore additional markup and only store innerText as data
if(col.stripHTML){
contents = (cell.innerText)? cell.innerText.trim(): '';
}
else{
contents = (cell.innerHTML)? cell.innerHTML.trim(): '';
}

if ( col && col._bAttrSrc ) {
var setter = _fnSetObjectDataFn( col.mData._ );
Expand Down
29 changes: 29 additions & 0 deletions js/model/model.defaults.columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,35 @@ DataTable.defaults.column = {
*/
"sName": "",


/**
* Defines whether the cell data includes the HTML content or not.
* This means that when the data contents of the cell are set, the innerText property is used rather than innerHTML.
*
* This is useful in environments where table data may be embedded in multiple levels of HTML after the <td> element for two reasons:-
* -DataTables extensions such as searchPanes can compare cell data without comparing HTML data.
* -Performance increase for processing tables which have a large amount of additional markup as less data is saved to memory. *
*
* @name DataTable.defaults.column.stripHTML
* @type bool
* @default false
*
* @example
* // Using `columnDefs`
* $(document).ready( function() {
* $('#example').dataTable( {
* "columnDefs": [
* {
* stripHTML: true,
* targets : '_all'
* }
* ]
* } );
* } );
*
*/
"stripHTML": false


/**
* Defines a data source type for the ordering which can be used to read
Expand Down