Export to excel
Export to excel
pehlewan
Posts: 4Questions: 1Answers: 0
I am trying to export all the rows using the buttons (see below). But clicking Export All has a strange behavior:
* if there are no selected rows it exports all the rows
* if there are selected rows, it exports only these
Is that the expected functionality?
buttons: [
{
extend: 'pageLength',
className: 'btn-success btn-sm'
},
{
extend: 'excelHtml5',
className: 'btn-success btn-sm',
text: 'Export All',
title: 'All',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'excelHtml5',
className: 'btn-success btn-sm',
text: 'Export Selected',
title: 'Selected',
exportOptions: {
modifier: {
selected: true
},
columns: ':visible'
}
}]
This discussion has been closed.
Answers
According to this example you will want to use this:
Kevin
This excludes the selected rows. Is there a way to have all of them? Already tried
Downloaded the latest version of the Select and used below modifier to fix.
I think the default value for selected is set to true somehow (?)
Yes - as of Buttons 1.5.0 this is expected. Funnily enough it was a reasonable common request, but yours is the first report since it has been implemented and it isn't what you expected! Win some, loose some .
There is some discussion on that in this example.
Allan
@allan: the example is wrong unfortunately. If you click on "Print all (not just selected)" all rows are printed excluding the selected ones! Thanks @pehlewan this is very helpful! Got trapped by this, too. Only passing this makes all records show up:
Found this in dataTables.buttons.js
From the comment "If no rows are selected, all rows will be exported." I infere that if some rows are selected not all rows might be exported which is actually true ...
Question is: will @pehlewan 's solution work in the longer term? Or will there be changes to the buttons extension?
Yes it will - that was the intention. As you say, the example is wrong - sorry about that. Fixed now.
Allan
Thanks a lot Allan! You're doing a great job!! Have a nice week end! The code below worked too but you need the quotes ...
If it did - that's fluke! Only
null
,undefined
,true
andfalse
(all as primitive values, not strings) are expected as values there.Allan
I think the "problem" lies with the fact that the code only checks if the value is true or false, otherwise it exports everything. Below would also work
It also checks for
null
andundefined
(the latter by it being not there).But yes, anything truthy would "work".
Allan