I am using Bootsfaces Datatable in a project to display a list of objects.
<h:form id="form">
<b:growl id="growl" allowDismiss="true"/>
<b:dataTable responsive="true" ajax="true" id="data_table" class="table table-responsive" value="#{adminCarrera_Bean.lista_carreraes}" var="carrera" paginated="true" csv="true" pdf="true" print="true" page-length="10">
<b:dataTableColumn value="#{carrera.carreranacionalidcarreranacional.nombrecarreranacional}" order="asc" label="Nombre">
</b:dataTableColumn>
<b:dataTableColumn value="#{carrera.facultadcodigoarea.nombrearea}" label="Facultad">
</b:dataTableColumn>
<b:dataTableColumn value="#{carrera.carreranacionalidcarreranacional.especialidadidespecialidad.nombreespecialidad}" label="Especialidad">
</b:dataTableColumn>
<b:dataTableColumn label="Estado">
<b:label text="#{adminCarrera_Bean.Translate_Estado(carrera.canceladacarrera)}" severity="#{adminCarrera_Bean.BooleanToSeveriy(carrera.canceladacarrera)}"/>
</b:dataTableColumn>
<b:dataTableColumn label="Acciones" style="width: 100px;">
<center>
<p:commandButton id="btnInfo" icon="fa fa-info" title="Información" update="form2" class="btn btn-info" action="#{adminCarrera_Bean.updateSelected_Carrera(carrera)}" oncomplete="$('#InfoModal').modal()" ajax="true">
</p:commandButton>
<p:blockUI block="body" trigger="btnInfo">
<div class="sk-cube-grid">
<div class="sk-cube sk-cube1"></div>
<div class="sk-cube sk-cube2"></div>
<div class="sk-cube sk-cube3"></div>
<div class="sk-cube sk-cube4"></div>
<div class="sk-cube sk-cube5"></div>
<div class="sk-cube sk-cube6"></div>
<div class="sk-cube sk-cube7"></div>
<div class="sk-cube sk-cube8"></div>
<div class="sk-cube sk-cube9"></div>
</div>
</p:blockUI>
<p:commandButton style="margin-left: 10px" class="btn btn-warning" id="btnEdit" update="form3" title="Editar" icon="fa fa-edit" action="#{adminCarrera_Bean.updateSelected_Carrera_toEdit(carrera)}" oncomplete="$('#EditModal').modal()" ajax="true">
</p:commandButton>
<p:blockUI block="body" trigger="btnEdit">
<div class="sk-cube-grid">
<div class="sk-cube sk-cube1"></div>
<div class="sk-cube sk-cube2"></div>
<div class="sk-cube sk-cube3"></div>
<div class="sk-cube sk-cube4"></div>
<div class="sk-cube sk-cube5"></div>
<div class="sk-cube sk-cube6"></div>
<div class="sk-cube sk-cube7"></div>
<div class="sk-cube sk-cube8"></div>
<div class="sk-cube sk-cube9"></div>
</div>
</p:blockUI>
</center>
</b:dataTableColumn>
</b:dataTable>
<b:commandButton id="btnADD" value="Adicionar Carrera" iconAwesome="plus" look="success" action="#{adminCarrera_Bean.cleanVariables()}" onclick="$('#AddModal').modal()" ajax="true">
<f:ajax render="form1"/>
</b:commandButton>
</h:form>
This code shows me a table on the screen with all the data of a Carrera object, that is, the table in this case has 4 columns. There is also a fifth column that allows operations on row data (Info and Edit), which open a modal each showing the necessary data. In the table it is stated that the data can be printed and the data exported to PDF. The problem is that it prints or exports exactly all the columns on the page, including the Actions column, which I do not need to print. Is there a way to select which columns you want to print / export? These are the captures of the table and the table when selecting the print button: Design of the page on the page Design of the table when printing
You can achieve that by abandoning the BootsFaces shortcuts csv="true"
, pdf="true"
, and print="true"
. Instead, put the Json object suggested by the Datatables.net documentation in a custom-options
attribute. That's a bit cumbersome, but it works, as the "sneak preview" showcase of the BootsFaces project shows. The resulting source code looks like so:
<b:dataTable responsive="true"
ajax="true"
id="data_table"
class="table table-responsive"
value="#{adminCarrera_Bean.lista_carreraes}"
var="carrera"
paginated="true"
page-length="10"
custom-options="dom: 'lfrtiBp',buttons: ['colvis','copy','csv',{extend: 'excelHtml5', exportOptions: {columns: [ 0, 1, 2, 3, 5 ]}},{extend: 'pdfHtml5', exportOptions: {columns: [ 0, 1, 2, 3, 5 ]}},'print']">