You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/grid/export/events.md
+206-4Lines changed: 206 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ To export a hidden Grid column that has its `Visible` parameter set to `false`,
41
41
42
42
*`Data` - `IEnumerable<object>` - assign a custom collection of data to be exported to Excel, [for example only the selected items in the Grid]({%slug grid-kb-export-selected-rows%}).
43
43
44
-
*`isCancelled` - `bool` - cancel the OnBeforeExcel event by setting the `isCancelled` property to `true`.
44
+
*`isCancelled` - `bool` - cancel the `OnBeforeExcel` event by setting the `isCancelled` property to `true`.
45
45
46
46
>caption Using the Grid OnBeforeExport with Excel export
47
47
@@ -253,9 +253,134 @@ To export a hidden Grid column that has its `Visible` parameter set to `false`,
253
253
}
254
254
````
255
255
256
-
### For Pdf Export
256
+
### For PDF Export
257
+
258
+
*`Columns` - `List<GridPdfExportColumn>` - a collection of all exportable columns in the Grid. These are all visible `GridColumn` instances. You can customize the following attributes of the Grid column before exporting it into PDF:
259
+
260
+
*`Width` - define the width of the column **in pixels**.
261
+
*`Title` - define the column title to be shown in the Excel file header.
262
+
*`NumberFormat` - provide an PDF-compatible number/date format
263
+
*`Field` - set the data bound field of the column.
264
+
265
+
To export a hidden Grid column that has its `Visible` parameter set to `false`, you can manually define an instance of the `GridPdfExportColumn` in the handler for the `OnBeforeExport` event and add that column to the `args.Columns` collection.
266
+
267
+
268
+
*`Data` - `IEnumerable<object>` - assign a custom collection of data to be exported to Excel, [for example only the selected items in the Grid]({%slug grid-kb-export-selected-rows%}).
269
+
270
+
*`isCancelled` - `bool` - cancel the `OnBeforeExcel` event by setting the `isCancelled` property to `true`.
271
+
272
+
>caption Using the Grid OnBeforeExport with PDF export
273
+
274
+
````RAZOR
275
+
@* This example shows the capabilities of the OnBeforeExport event when exporting the Grid to PDF. *@
276
+
277
+
@* Required by BuiltInNumberFormats in the OnBeforePDFExport handler *@
278
+
@using Telerik.Documents.SpreadsheetStreaming
279
+
280
+
@* Required by GridPdfExportColumn in the OnBeforePDFExport handler *@
281
+
@using Telerik.Blazor.Components.Grid
282
+
283
+
<TelerikGrid Data="@GridData"
284
+
Pageable="true"
285
+
Sortable="true"
286
+
@bind-SelectedItems="@SelectedItems"
287
+
SelectionMode="@GridSelectionMode.Multiple"
288
+
Resizable="true"
289
+
Reorderable="true"
290
+
FilterMode="@GridFilterMode.FilterRow"
291
+
Groupable="true"
292
+
Width="700px">
293
+
294
+
<GridToolBarTemplate>
295
+
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to PDF</GridCommandButton>
296
+
<label class="k-checkbox-label"><TelerikCheckBox @bind-Value="@ExportAllPages" />Export All Pages</label>
// Export only the SelectedItems instead of the Grid data
351
+
args.Data = SelectedItems;
352
+
}
353
+
354
+
// Set IsCancelled to true if you want to prevent exporting
355
+
//args.IsCancelled = false;
356
+
}
357
+
358
+
protected override void OnInitialized()
359
+
{
360
+
GridData = Enumerable.Range(1, 50).Select(x => new SampleData
361
+
{
362
+
ProductId = x,
363
+
ProductName = $"Product {x}",
364
+
UnitsInStock = x * 2,
365
+
Price = 3.14159m * x,
366
+
Discontinued = x % 4 == 0,
367
+
ReleaseDate = DateTime.Now.AddDays(-x)
368
+
}).ToList();
369
+
370
+
SelectedItems = GridData.Take(5);
371
+
}
372
+
373
+
public class SampleData
374
+
{
375
+
public int ProductId { get; set; }
376
+
public string ProductName { get; set; }
377
+
public int UnitsInStock { get; set; }
378
+
public decimal Price { get; set; }
379
+
public bool Discontinued { get; set; }
380
+
public DateTime ReleaseDate { get; set; }
381
+
}
382
+
}
383
+
````
259
384
260
385
## OnAfterExport
261
386
@@ -413,12 +538,89 @@ The `OnAfterExport` event fires after [OnBeforeExport](#onbeforeexport) and befo
413
538
414
539
### For Pdf Export
415
540
416
-
xzxz
541
+
*`Stream` - `MemoryStream` - The output of the PDF export as a memory stream. The stream itself is finalized, so that the resource does not leak. To read and work with the stream, clone its available binary data to a new `MemoryStream` instance.
542
+
543
+
````RAZOR
544
+
@* Get the output of the PDF export as a MemoryStream *@
545
+
546
+
@using System.IO
547
+
548
+
<TelerikGrid Data="@GridData"
549
+
Pageable="true"
550
+
Sortable="true"
551
+
@bind-SelectedItems="@SelectedItems"
552
+
SelectionMode="@GridSelectionMode.Multiple"
553
+
Resizable="true"
554
+
Reorderable="true"
555
+
FilterMode="@GridFilterMode.FilterMenu"
556
+
Groupable="true"
557
+
Width="700px">
558
+
559
+
<GridToolBarTemplate>
560
+
<GridCommandButton Command="PdfExport" Icon="@SvgIcon.FilePdf">Export to PDF</GridCommandButton>
561
+
<label class="k-checkbox-label"><TelerikCheckBox @bind-Value="@ExportAllPages" />Export All Pages</label>
0 commit comments