Is there a way to use fnCellRender AND strip html?

Is there a way to use fnCellRender AND strip html?

Steve_WebtronSteve_Webtron Posts: 19Questions: 0Answers: 0
edited January 2014 in General
When you export to csv, it strips all the html in the cells,
I would like to use fnCellRender to also replace some data
(like removeing BR's for excel's sake)

[code]
"fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
return '"'+sValue.replace(/
|/g,"\n")+'"';
}
[/code]

However this leaves me with all the nasty etc tags back in the data.

Is there a way to get the best of both worlds?

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Set sType to be `html` . It isn't automatically detected since fnCellRender runs after the type detection.

    Allan
  • Steve_WebtronSteve_Webtron Posts: 19Questions: 0Answers: 0
    That's awesome thanks,

    What we've been doing is going through several pages and adding dataTables class to the tables,
    We then just initialize all the dataTables with that class when our "frame" loads.

    Can I set this with javascript on a page by page basis?

    Or would it just be safe to set all columns to html (because I'm finding anything and everything in these tables)
  • Steve_WebtronSteve_Webtron Posts: 19Questions: 0Answers: 0
    Well more importantly, you mention fnCellRender runs after the type detection.
    So the sType was already run?
    if it was set with "aoColumnDefs": is is lost now?

    Should I just find a way to put it inside the fnCellRender function?
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    > Or would it just be safe to set all columns to html (because I'm finding anything and everything in these tables)

    Yes if you only have string data, no if you don't - since numbers wouldn't be sorted correctly.

    > if it was set with "aoColumnDefs": is is lost now?

    If set via sType then the automatic detection does not run and it just takes your value.

    I'd say that mRender is probably a better solution for you here then fnCellRender . fnCellRender is really designed for added events etc to the created DOM element - while mRender is what does the formatting.

    Allan
  • Steve_WebtronSteve_Webtron Posts: 19Questions: 0Answers: 0
    edited January 2014
    I was just taking the only other answer I found in the forums, about removing
    from excel exports to keep the data all in the same cell.

    Thanks again though, I will look at mRender.

    Since it is for Export, I believe that I may have to touch the underlying data... which mRender says it does not do.
This discussion has been closed.