Printing
FastGrid documentation
Which rows and columns are printed.
0 -
none - prints nothing,
1 -
focused cell(s) - prints focused cells only,
2 -
selected rows / columns or
focused cell(s) - prints selected rows and chosen rows with selected columns and chosen columns.
If no columns selected, prints selected rows and chosen rows with all columns except not chosen columns.
If no rows selected, prints selected columns with all rows except not chosen rows.
If no selection, prints focused cells.
3 -
selected rows / columns or
focused row(s) - like
2, but if no selection, prints focused rows with all columns except not chosen columns.
If row selection is restricted and column selection is permitted, prints focused columns with all rows except not chosen rows.
4 -
focused cells or
selected rows / columns or
focused cell - prints focused cells if permitted focusing rectangle by
Focus>=
2, otherwise like
2.
5 -
focused cells or
selected rows / columns or
focused row(s) - prints focused cells if permitted focusing rectangle by
Focus>=
2, otherwise like
3.
6 -
all rows and columns - prints all rows and all columns except those not chosen in export menu.
Comma separated list or array of row ids that will be printed as chosen rows according to
Printing.
If the item starts by "
-", it is marked as not chosen and is not printed as not chosen rows according to
Printing.
If there is item named "
-", it represents all applicable rows as not chosen.
If there is item named "
*", it represents all applicable rows as chosen. For example "*,-Row3" chooses all rows except Row3.
Comma separated list or array of column ids that will be printed as chosen columns according to
Printing.
If the item starts by "
-", it is marked as not chosen and is not printed as not chosen columns according to
Printing.
If there is item named "
-", it represents all applicable columns as not chosen.
If there is item named "
*", it represents all applicable columns as chosen. For example "*,-Col1" chooses all columns except Col1.
Which rows are printed:
NoPrint - prints also rows with
NoPrint =
1.
Collapsed - prints also collapsed children.
Hidden - prints also manually hidden rows.
Filtered - prints also filtered rows.
Deleted - prints also deleted rows.
Parents - prints also all parents of printed rows, if printing only selected rows.
Children - prints also all children of printed rows, if printing only selected rows.
Block - prints also other rows in
Block.
Which columns are printed:
NoExport - prints also columns with
NoPrint =
1.
Collapsed - prints also collapsed children.
Hidden - prints also manually hidden columns.
Filtered - prints also filtered columns.
Deleted - prints also deleted columns.
Parents - prints also all parents of printed columns, if printing only selected columns.
Children - prints also all children of printed columns, if printing only selected columns.
Block - prints also other columns in
Block.
Comma separated list or array of toolbar ids that will be printed. By default all the toolbars by marked to not be printed.
If the item starts by "
-", it is marked as not chosen and is not printed as not chosen rows according to
Printing.
If there is item named "
-", it represents all applicable rows as not chosen.
If there is item named "
*", it represents all applicable rows as chosen. For example "*,-Row3" chooses all rows except Row3.
By default the toolbars are not printed due default value "-".
&
1 if set, does not split Block of rows to more pages.
&
2 if set, does not split Block of columns to more pages.
Maximal row level
L that can be printed as the first row on page. To not split row tree between pages.
Maximal column level
L that can be printed as the first column on page. To not split column tree between pages.
If or which side icons will be printed.
0 - none, &
1 - all left icons, &
2 - all right icons, &
4 - all text icons.
Or specify comma separated string of icon names to print only them, e.g.
PrintIcons="List,Date".
If generating print report is taking more than this time in milliseconds, progress message is shown during printing.
If set to
0, the printing is always synchronous and cannot be cancelled during long process.
Maximum pages that can be printed at once.
The browser tab can crash, if it is printing too many pages!
For pages bigger than A4 or zoomed pages to fit width / height, the maximal pages count is decreased accordingly.
If set, after printed grid is generated, it runs immediately the printing, usually shows the browser print dialog.
If set to
2, it closes the printed grid immediately after run printing.
If not set, it displays the printed html in browser and a user must print it manually. The printed html is removed after any click or pressing Esc.
If set to
1, it shrinks the printed grid pages to be always printed whole regardless on page size, orientation and margin chosen in system / browser print dialog.
If set to
2, it works as
1 and also resizes too small grid pages to fill at least one direction of the printed page.
Using this attributes cancels the requirement to choose the same pages size, orientation and margins in FastGrid print dialog and system / browser print dialog.
Shrinks the printed grid to be printed in one page in given or both directions.
0 = Real size,
1 = Width,
2 = Height,
3 = Single page .
If not set
PrintZoomFit, it sets it automatically to 1.
Paper size used for printing.
It can be: Auto, Letter, Legal, Ledger, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, B0, B1, B2, B3, B4, B5.
In PDF it sets also the PDF page size. In printing it does
not change the paper size in browser print dialog.
Paper orientation used for printing, 0 - portrait, 1 - landscape.
In PDF it sets also the PDF page orientation. In printing it does
not change the paper orientation in browser print dialog.
Paper left or right margin in mm used for printing.
In PDF it sets also the PDF page horizontal margins. In printing it does
not change the page horizontal margins in browser print dialog.
Paper top or bottom margin in mm used for printing.
In PDF it sets also the PDF page vertical margins. In printing it does
not change the page vertical margins in browser print dialog.
Width of page for printing, in pixels.
If the printed grid is wider than this value, it is split to more pages horizontally.
The grid is always split between columns and depending on
PrintBlock.
Every page contains all columns with
NoPrint =
-1 set and next set of columns with
NoPrint = 0.
If set to
0, the printed grid is not split to pages horizontally. Also items for page width are hidden from print columns menu.
Default value 695 corresponds with page A4 portrait, 96 DPI and 13mm margin on both sides. (1mm = 96/25.4px)
Remember, this attribute cannot control the final printing page chosen by user in printing dialog!
Height of page for printing, in pixels.
If the printed grid is higher than this value, it is split to more pages vertically.
The grid is always split between rows and depending on
PrintBlock.
Every page contains all rows with
NoPrint =
-1 set and next set of rows with
NoPrint = 0.
If set to
0, the printed grid is not split to pages horizontally. Also items for page height are hidden from print columns menu.
Value 1024 corresponds with page A4 portrait, 96 DPI and 13mm margin on both sides. (1mm = 96/25.4px)
Remember, this attribute cannot control the final printing page chosen by user in printing dialog!
Minimal width of printed page in pixels. If it less than 1, it is ratio of
PrintPageWidth.
It is applied only if set PrintZoomFit.
If the printed page is narrower than this value, it is merged to previous or next page. It means one printed page can be wider up to by
PrintPageMinWidth * 2.
Minimal height of printed page in pixels. If it less than 1, it is ratio of
PrintPageHeight.
It is applied only if set PrintZoomFit.
If the printed page is smaller than this value, it is merged to previous or next page. It means one printed page can be higher up to by
PrintPageMinHeight * 2.
Html code printed above first page. It must be valid enclosed html code, its height is calculated to reduce the first page height.
It is printed always into the first page, it is never split to pages. It must be smaller than the first page.
The string can contain $XXX strings to replace by translation and also JavaScript code in
{ }, that can use variables:
RPages as total count of printed row pages,
CPages as total count of printed column pages,
Pages as total count of printed pages.
Html code printed below last page. Its height does not reduce printed height of grid on last page, so it can be split to the next page, if required. It can contain content like
PrintPrefix
Html code printed above every page. It must be valid enclosed html code, its height is calculated to reduce page height.
The string can contain $XXX strings to replace by translation and also JavaScript code in
{ }, that can use variables:
RPage as printed row page (from 1),
RPages as total count of printed row pages,
CPage as printed column page (from 1),
CPages as total count of printed column pages,
Page as printed page (from 1),
Pages as total count of printed pages.
Grid as grid
Sheet or
id.
For example:
PrintPagePrefix:"Rows: {RPage} / {RPages}, Cols: {CPage} / {CPages}<br>Pages: {Page} / {Pages}"
Html code printed below every page, see
PrintPagePrefix.
List of pages to print, it contains page numbers from 1, pages in ranges are separated by "-" or "~", the page ranges and single pages are separated by "," and ";".
For example
"1-2;4;6-9" to print pages 1,2,4,6,7,8,9.
If it can show page breaks in (not printed) grid to mark which row / columns will be printed to which page.
-1 - The page breaks are hidden and cannot be shown.
0 - The page breaks are hidden and can be shown.
1 - The page breaks are shown and can be hidden.
Can slow down painting large grids!
2 - The page breaks are shown and can be hidden. They are updated during resizing.
Can slow down painting and resizing large grids!
If row count exceeds this value, the showing page breaks will be disabled. To speed up paint and resizing.
Grid method void
SetShowPrintPageBreaks
(int value, bool always = 0)
Sets value to
ShowPrintPageBreaks, except if set to -1.
If set
always, it repaints print page breaks also if not changed.
If set and
Overlay is set, it resizes the print area for all overlaid cells to be printed fully.
For PDF export it resizes also by column span.
Comma separated string or array of items shown in Print menu. Set it to "" to not show the menu. It can contain "-" item as separator. Case sensitive. It can contain these keywords:
Print size options:
PageSize (changes
PrintPageSize attribute, chooses item from popup list),
PageLandscape (changes
PrintPageLandscape attribute, checkbox),
MarginWidth (changes
PrintMarginWidth attribute, inputs number as milimeters),
MarginHeight (changes
PrintMarginHeight attribute, inputs number as milimeters),
FitSize (changes
PrintFitPage attribute, chooses item from popup list),
SplitBlock (changes
PrintBlock attribute, checkbox),
SplitTree (changes
PrintMaxRowLevel and
PrintMaxColLevel attributes, checkbox),
Pages (changes
PrintPages attribute, inputs numbers and their ranges as printed pages),
Size (displays expected count of printed pages according to the chosen options),
Rows and columns: (changes
PrintRowsType and / or
PrintColsType:
Collapsed (&
2, children of collapsed parents),
Hidden (&
4, manually hidden),
Filtered (&
8, hidden by filter),
AllHidden (&
14, all hidden by any reason),
Deleted (&
16, deleted, but not removed),
Children (&
32, also all children),
Parent (&
64, also all parents),
CollapsedRows,
HiddenRows,
FilteredRows,
AllHiddenRows,
DeletedRows,
ChildRows,
ParentRows (control only
PrintRows),
CollapsedCols,
HiddenCols,
FilteredCols,
AllHiddenCols,
DeletedCols,
ChildCols,
ParentCols (control only
PrintCols).
Other options:
Items (changes
Printing attribute, chooses items from popup list),
Sheets (changes
NoPrint attribute of all sheets in book, chooses items from popup list),
MoreSheets (changes
PrintGrids attribute, checkbox),
To hide disabled items in the menu set:
Dialogs:{ Print:{ Script:{ HideDisabled:1 } } }.
To show the menu in two columns set:
Dialogs:{ Print:{ Script:{ Columns:2 } } }.
If set to
0, it prints only this sheet.
If set to
1, it prints all sheets together according to their
NoPrint attribute.
If set to
string as comma separated list of grid ids, prints these grids together.
If set, loads all children of rows with
Children attribute on print, if
PrintRowsType contains "
Collapsed".
If the grid printing is restricted.
Only for PrintGrids = 1.
-2 - grid is printed always and not shown in sheets in Print menu,
-1 - grid is printed always,
0 - grid is printed only if it is not
Hidden,
1 - grid is not printed,
2 - grid is not printed and not shown in sheets in Print menu.
If printing the row / column data is restricted.
-1 printed always either if hidden and hidden are not printed,
0 printed,
1 not printed,
2, not printed either if set
PrintRowsType flag
NoPrint /
PrintColsType flag
NoPrint.
If printing the toolbar data is restricted.
-1 printed always either if hidden and hidden are not printed,
0 printed,
1 not printed.
If the row is printed to every row page or if the column is printed to every column page.
By default it is set to 1 in Header row and 0 for all other rows and columns.
If set, used instead of
AutoRemove to get rows / columns for print when the part adds rows / columns automatically by
Auto.
Actions
Print
(int target = 0)
OnClickPrint
Prints the grid. Shows dialog with print settings and next prints the grid to printer.
Grid method any
Print
(int width = null, int height = null, int fit = null, any test = 0)
Prints the grid. It is asynchronous method.
width is
PrintPageWidth,
height is
PrintPageHeight,
fit is
PrintFitPage.
If set
test =
1, it just calculates expected printed pages count and returns [rowpagescount,colpagescount,pagecount,maxpagecount], where
pagecount is set if printed more grids and
maxpagecount is set if reached
MaxPrintPages.
If set
test as object, it behaves as
1 and is used to read these print attributes from:
PrintGrids, PrintRows, PrintCols, PrintRowsType, PrintColsType, PrintPageWidth, PrintPageHeight, PrintFitPage, Printing, PrintBlock, PrintMaxRowLevel, PrintMaxColLevel.
API event bool
OnPrint
(Grid grid)
Called before the grid is printed. Return true to suppress the action.
API event void
OnPrintCreate
(Grid grid)
Called during printing, after grid layout is modified and prepared to generate the print html, but before the print html was generated.
API event void
OnPrinted
(Grid grid, bool cancelled)
Called after the print html was generated and put to the page. Called before the print() is called.
If set
cancelled, the report was cancelled by a user and will not be printed.
Print to PDF
Printing to PDF requires
server script that receives actual configuration, prints the grid to HTML using
FGrid.PrintFastGrid() API function, converts the HTML to PDF by some server side converter, e.g. Chrome Headless and returns the PDF back to client.
FastGrid package provides the server script for printing to PDF using Chrome Headless in these languages:
ASP.NET C# and
Visual Basic,
Java JSP,
PHP and
NodeJS JavaScript.
To permit printing to PDF the grid must have set at least
PdfUrl.
Url of server script that will print the grid to PDF.
It can be string as direct url or object with
Url attribute as the url and
Param as object with parameters (name=value) to send to the Url as form POST.
The Url can contain string
*Grid to be replaced by url to FGridE.js script, without the script name and the last "/".
To the server there are sent data in POST request:
File - chosen file name to save the PDF as, without extension.
Data - saved configuration data according to
PdfFlags, only if
not set
PdfHtml.
Html - full html page that shows actual grid - it contains reference to FastGrid script and all to all input data urls and also saved configuration according to
PdfFlags. Filled only if set
PdfHtml. The html has replaced entities for characters < > &.
Default url leads to PHP script Pdf.php in Pdf directory. There available also files in other scripts Pdf.aspx, Pdf.jsp and for Node server Pdf.js.
Chooses what to sent to the
PdfUrl.
0 - it sends only configuration data according to
PdfFlags in
Data attribute.
The server script must generate or use the html that will create FastGrid with original data, adds here the configuration data and prints the grid by
FGrid.PrintFastGrid().
Use for more complex grid that require specific communication or its input data are added to the grid manually.
1 - it sends generated full html page in
Html attribute.
The server script just saves this html and runs it in the pdf to html converter. The html contains all required information and urls to generate the grid for printing.
Use for simpler grids that can use static urls and data to simplify the server side code.
2 - the same as
1, but does not send to server any
Sources data.
Base HTML code used to generate HTML page with FastGrid to be printed to PDF.
It can contain two keywords to replace:
%Script will be replaced by FGridE.js full url, including quotes and
%Source will be replaced by full
Sources object to create actual FastGrid.
Cfg string[]
PdfFlags
["Print,Selected,Hidden,Collapsed,Cookie,Changes,AddData,Defer"] / ["Print,Cfg,DefCells,FCols,Cols,FBody,Body,VArray,AArray,NoE,Images"] GetCfgAttr SetCfgAttr
Comma separated string or array of flags to save changes, configuration or data, to be sent to
PdfUrl in
Data or within
Html. It can contain flags applicable for
GetData API method.
It can contain also special flag "
Defer", to load the data after grid initialization, like source
Defer =
2. It is
not suitable for Sheet or when sending whole data.
Name of the generated PDF file to save. Without extension. It is sent to
PdfUrl in
File POST attribute.
Comma separated string or array of items shown in Print PDF menu. Set it to "" to not show the menu. It can contain "-" item as separator. Case sensitive. It can contain this keyword:
File (changes
PdfName attribute, edits the file name in input).
Other keywords are the same as in PrintMenu.
Comma separated string or array of items shown in Print + PDF menu (for both print to printer and to PDF). Set it to "" to not show the menu (it will print to printer). Case sensitive. It can contain "-" item as separator. It can contain this keyword:
File (changes
PdfName attribute, edits the file name in input).
Other keywords are the same as in PrintMenu.
If PDF export relies on Chrome headless, this attribute avoids bug in the Chrome headless.
It should be set to "", if the Chrome version has this bug corrected.
If set to page size like "A4" or "Letter", it avoids bug in setting @page size that presets A4 or US Letter and collides with
PrintZoomFit and
PrintFitPage.
String added before all custom relative urls. It should end by slash '/'.
It is also generated from actual url when
Save data by "Print" option.
Actions
Pdf
(int target = 0)
OnClickPdf
Prints the grid to PDF. Shows dialog with print pdf settings and next sends the print html or settings to server to convert to PDF and download back.
FGrid function Grid
PrintFastGrid
(any src, any add = null, function onfinish = null)
Creates new FastGrid, loads it synchronously, if possible, and renders it for printing to the page body. Returns created object.
src contains json data or urls returning json data to load grid from, see
FastGrid()
add can be string or object data loaded after loading
src.
If set
onfinish, the function is called after the grid is rendered.
For example:
FGrid.PrintFastGrid(["Def.js","Data.js"]);
API event bool
OnPdf
(Grid grid)
Called on client side before the grid data is created and sent to server to print to PDF. Return true to suppress the action.
On server side there are called OnPrint / OnPrintCreate / OnPrinted API events.
API event bool
OnPdfSend
(Grid grid, HTMLElement form)
Called on client side after the grid data is created and before the form is submitted to server to print to PDF. Return true to suppress the action.