Rendering Ampersands in DataTables
Rendering Ampersands in DataTables
MattSyp
Posts: 3Questions: 0Answers: 0
Allan,
I ran into an issue with displaying data with ampersands in IE8 (I don't have a choice to not support it so roll with me). There was a post that I linked to that described the same problem I was having and I came up with a simple solution that you might want to check out. I changed the _fnSetCellData function to check if the val was a string and had an ampersand in it. If it did, then I replaced the ampersand and everything started to display properly. It is a small fix, but did what I needed it to do.
There might be a better way to do this, but I have tested this in IE8, IE9, IE10, Chrome and Firefox and none had an issue rendering or saw any performance degradation.
Original Article:
http://datatables.net/forums/discussion/4113/special-characters-specifically-ampersand-in-json-server-side-population-not-displaying-in-grid/p1
[code]
/**
* Set the value for a specific cell, into the internal data cache
* @param {object} oSettings dataTables settings object
* @param {int} iRow aoData row id
* @param {int} iCol Column index
* @param {*} val Value to set
* @memberof DataTable#oApi
*/
function _fnSetCellData( oSettings, iRow, iCol, val )
{
var oCol = oSettings.aoColumns[iCol];
var oData = oSettings.aoData[iRow]._aData;
// MattSyp: Replace the & with & in val so IE8 handles & correctly.
if (typeof val === "string" && val.indexOf("&") > -1) { val = val.replace(/&/g, "&");}
oCol.fnSetData( oData, val );
}
[/code]
I ran into an issue with displaying data with ampersands in IE8 (I don't have a choice to not support it so roll with me). There was a post that I linked to that described the same problem I was having and I came up with a simple solution that you might want to check out. I changed the _fnSetCellData function to check if the val was a string and had an ampersand in it. If it did, then I replaced the ampersand and everything started to display properly. It is a small fix, but did what I needed it to do.
There might be a better way to do this, but I have tested this in IE8, IE9, IE10, Chrome and Firefox and none had an issue rendering or saw any performance degradation.
Original Article:
http://datatables.net/forums/discussion/4113/special-characters-specifically-ampersand-in-json-server-side-population-not-displaying-in-grid/p1
[code]
/**
* Set the value for a specific cell, into the internal data cache
* @param {object} oSettings dataTables settings object
* @param {int} iRow aoData row id
* @param {int} iCol Column index
* @param {*} val Value to set
* @memberof DataTable#oApi
*/
function _fnSetCellData( oSettings, iRow, iCol, val )
{
var oCol = oSettings.aoColumns[iCol];
var oData = oSettings.aoData[iRow]._aData;
// MattSyp: Replace the & with & in val so IE8 handles & correctly.
if (typeof val === "string" && val.indexOf("&") > -1) { val = val.replace(/&/g, "&");}
oCol.fnSetData( oData, val );
}
[/code]
This discussion has been closed.