打印/导出引导表数据表中的选定列

时间:2019-04-10 15:29:04

标签: java jsf datatable bootsfaces

我正在项目中使用Bootsfaces数据表来显示对象列表。

<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&oacute;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>

此代码向我显示了屏幕上的一个表,其中包含Carrera对象的所有数据,也就是说,本例中的表有4列。第五列还允许对行数据(信息和编辑)进行操作,这将打开一个模态,每个模态均显示必要的数据。在该表中说明可以打印数据,并将数据导出为PDF。问题在于它可以完全打印或导出页面上的所有列,包括“动作”列,而我不需要打印这些列。有没有一种方法可以选择要打印/导出的列?这些是表格和选择打印按钮时表格的捕获: Design of the page on the page Design of the table when printing

1 个答案:

答案 0 :(得分:0)

您可以通过放弃BootsFaces快捷键csv="true"pdf="true"print="true"来实现。而是将the Datatables.net documentation建议的Json对象放在custom-options属性中。这有点麻烦,但是可以像"sneak preview" showcase of the BootsFaces project shows一样工作。产生的源代码如下所示:

<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']">