This is a migrated thread and some comments may be shown as answers.

Replacing selected column content with empty row before pdf export

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Desarrollo.BC
Top achievements
Rank 1
Desarrollo.BC asked on 27 Jun 2017, 06:47 PM

Hello,

I need to replace the content of the unselected rows with empty string, or replace with an empty row, upon doing a PDF export.

For example if I have the following grid:

ID      Description

1        Row 1

2        Row 2

3        Row 3

 

If I leave row 2 unselected it should be exported the following way:

ID      Description
1        Row 1

3        Row 3

 

Here is my code:

 

  @(Html.Kendo().Grid(Model)
                .Name("Grid")
                .ToolBar(toolbar => toolbar.Create().Text("Nuevo").HtmlAttributes(new { @class = "" }))
            .ToolBar(tools => tools.Pdf().Text("Imprimir"))
            .Pdf(pdf => pdf
            .AllPages()
            .AvoidLinks()
            .PaperSize("A4")
            .Scale(0.8)
            .Margin("2cm", "1cm", "1cm", "1cm")
            .RepeatHeaders()
            .TemplateId("page-template")
            .FileName("Ficha.pdf")
            .ProxyURL(Url.Action("Pdf_Export_Save", "Grid")))
            .Pageable(pager => pager
   .Refresh(true)
)
            .Columns(columns =>
            {
                columns.Bound(p => p.IdFicha).Title("Numero");
                columns.Bound(p => p.Fecha).Format("{0:dd/MM/yyyy}");
                columns.Bound(p => p.Descripcion).Title("Descripción");
                columns.Bound(p => p.Comentarios);
                columns.ForeignKey(x => x.IdCliente, (System.Collections.IEnumerable)ViewData["clientes"], "IdCliente", "Nombre").Hidden();
          
                columns.Command(command =>
                {
                    command.Edit().HtmlAttributes(new { @class = "btn btn-primary" })
                 .Text("Editar")
                 .UpdateText("Guardar")
                 .CancelText("Cancelar");
                    command.Destroy().Text("Eliminar");

                });

            })
             .Editable(editable => editable.Mode(GridEditMode.PopUp).Window(w => w.Title("Fichas")))
    .Pageable(p => p
                .Messages(m => m
                    .Display("Mostrando {0}-{1} de {2} registros")
                    .Empty("No se encontraron registros")
                    .First("Ir a la primera página")
                    .Last("Ir a la última página")
                    .Next("Ir a la página siguiente")
                    .Previous("Ir a la página anterior")
                )
)
.DataSource(dataSource => dataSource
        .Ajax()
    .Read(read => read.Action("Ficha_Read", "Home").Data("additionalData").Type(System.Web.Mvc.HttpVerbs.Post))
    )
    .Sortable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
    .Pageable(x => { x.Enabled(false); })
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Model(model => model.Id(p => p.IdFicha))
        .Destroy(update => update.Action("Ficha_Destroy", "Home"))
        .Update(update => update.Action("Ficha_Update", "Home"))
        .Create(update => update.Action("Ficha_Create", "Home").Data("additionalData").Type(System.Web.Mvc.HttpVerbs.Post))
     )
    .Events(e => e.PdfExport("PdfExport"))

<script>

  function PdfExport(e) {
    
    if (!exportFlag) {
      e.sender.showColumn(3);
      e.preventDefault();
      exportFlag = true;

      setTimeout(function () {
        e.sender.saveAsPDF();
      });
    } else {
        e.sender.hideColumn(3);

      exportFlag = false;
    }

  }



</script>

 

 

Thanks

 

 

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 29 Jun 2017, 01:27 PM
Hi Servando,

It is possible to hide the rows you don't want to export when pdfExport event is fired and then restore them when the exporting is done.

I have assembled a sample (export-selected.zip) which illustrates the aforementioned approach.

However if this approach does not match your requirements you can use Telerik PdfProccesing to customize the exported pdf server side with easy to use API which allows code-only generation of PDF documents.


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Desarrollo.BC
Top achievements
Rank 1
answered on 29 Jun 2017, 04:30 PM

Hello Georgi,

Thank you for your response.

Using your example I was able to read the cell data for the selected rows but when I edit the data it is not reflected on the grid:

var data = $('#grid').data('kendoGrid')._data[i].FirstName = "";

 

Is there a way to do this correctly without affecting the actual data?

0
Desarrollo.BC
Top achievements
Rank 1
answered on 29 Jun 2017, 07:17 PM

I figured it out, added an OnChange function and had to refresh the grid before the changes would take effect.

    function onChange(arg) {
        $('#grid').data('kendoGrid').dataSource.at(selected[0].rowIndex).FirstName = '';
        $('#grid').data('kendoGrid').refresh();
}

 

Thanks!

Tags
Grid
Asked by
Desarrollo.BC
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Desarrollo.BC
Top achievements
Rank 1
Share this question
or