kendo-ui print selected rows remote service

I followed the article outlined here: https://docs.telerik.com/kendo-ui/knowledge-base/grid-pdf-export-selected-rows-only

However the article does not account for server-side paging. In my webpage, I setup the grid just like the example has it setup with the only exception in that I'm using server-side paging. I click on the Export to PDF button, the grid on the webpage hides the unselected rows, it generates and saves the PDF, and then the unselected rows are visible again on the webpage. The difference is that once I open up the PDF document, the unselected rows are all visible in the document.

1 answer

  • answered 2019-11-14 16:36 David

    Ultimately what I wound up doing was iterating through all of the selected records, pushing their unique ID to a filter, and inside my dataSource's read transport I checked if a flag was set that indicates that the dataSource is being read due to the grid being exported. If the flag is set then I pass my unique ID filter to the request.

    pdfExport: function (e) {
        if (!isExportingPdf) {
            e.sender.hideColumn(1); // selectable column
            isExportingPdf = true;
    
            filter.Ids = Object.keys(e.sender._selectedIds).join(",");
    
            e.promise.done(function () {
                e.sender.showColumn(1);
                isExportingPdf = false;
    
                delete filter.Ids;
                _dataSource.read();
            });
        }
    }