Exporting datatable to Excel - Showing [object object]
Exporting datatable to Excel - Showing [object object]
Hi there,
I'm using DataTables and Angular Datatables. I get my Data from an ajax request and then user renderWith to render my data. This works fine, except when i have "dynamic objects" as you can see here.This is an example of a field and how i work the data:
DTColumnBuilder.newColumn(null).withTitle('BoatType').withOption('width','10%').notSortable(),
then i have:
function createLineBoatType(data) {
var boatTypes = getAllBoatTypes(data);
var str = "";
if (boatTypes.length === 1) {
str += "<td class='text-center vertical' >" + EnumsFactory.getDescEnum(boatTypes[0], 'boatsType') + "</td>";
} else {
str = "<td class='col-no-padding'>
" + EnumsFactory.getDescEnum(boatTypes[boatType], 'boatsType') + " |
</td>";
}
return str;
}
and then:
$(col[rowIdx]).replaceWith(createLineBoatType(data));
So ye, i've been searching all over the place as the rendered HTML it's all good, but! the excel export does not show what the HTML shows, rather it shows [object object], i have no clue of how i can solve this. I know this issue comes from the fact that i have null in here DTColumnBuilder.newColumn(null).withTitle('BoatType').withOption('width','10%').notSortable(),
but is it possible to get around this issue using this datatable construction architecture?
Tks in advance and sorry i don't know how to make those fancy code snipets
Answers
It looks like you are manipulating the DOM yourself - which means that DataTables won't know about the new values. You could use
row().invalidate()
, or use a rendering function to create the HTML within a DataTables context.Allan