TreeGrid v6.0
Print grid
User can print grid by clicking to Print button on toolbar.
TreeGrid opens new window and renders here the grid again and calls standard window.print method to show printing dialog and print the grid. The printing process itself cannot be controlled by JavaScript at all.
The grid rendered for printing does not show scrollbars, but displays the whole grid. It does not show right side pager. All other parts visibility can be controlled by CanPrint attributes.
Because TreeGrid uses background images, a user must have permitted “Printing background images” in his browser to successfully print the grid.
<I> int CanPrint [0/1/2] new 6.0; upd 7.1.
If the row will be printed.
0 - never, 1 – once if visible, 2 - on every page (only for fixed and space rows) if visible,
3 – (new 7.1) once always, 4 – (new 7.1) on every page (only for fixed and space rows) always
By default Toolbar has 0, Header has 2 and all other rows have 1.
<C> bool CanPrint [0/1] new 6.0 .
If the column will be printed.
By default Panel has 0 and other columns 1.
<cell> int CanPrint [1] new 7.1 .
If the cell will be printed. Useful especially for Space cells.
0 - never, 1 – if visible, 2 - always.
<Cfg> int PrintLocation [0] new 7.1.
Where the printable grid will be shown
0 – new window with PrintWindowProp properties
1 – new window with the same properties as the main window, ignores PrintWindowProp
2 – into the main tag instead of actual grid, like with NoVScroll / NoHScroll settings, ignores PrintCSS, PrintHead and PrintWindowProp
3 – into the same page, instead of the page content, ignores PrintCSS, PrintHead and PrintWindowProp
To modify other page content for printing use OnPrintFinish and restore the original in OnPrintClose.
<Cfg> int PrintPrint [1] new 7.1.
How the grid will be printed
0 – nothing will be shown
1 – print dialog will be shown
2 – alert for manual printing will be shown, remember to permit printing icons in the browser by PrintLocation.
3, 4 - reserved
5 – print preview in IE will be shown if permitted the ActiveX, otherwise like 1
6 – print preview in IE will be shown if permitted the ActiveX, otherwise like 2
<Cfg> string[] PrintGrids new 7.1.
To print more grids at once.
A list of grid ids, comma separated, to print them all in one print job, at the same page.
Set individual PrintPrefix / PrintPostfix to separate or structure the grids on page.
The PrintLocation, PrintPrint, PrintCSS, PrintHead and PrintWindowProp are read from the actual grid, the other printing properties from the individual grids.
If set PrintLocation = 2, all grids are replaced inside their main tags, for other options are printed in the listed order.
<Cfg> bool PrintExpanded [0] Saved to cookies, to not load it, set PrintLap=’1’ renamed 6.0;upd 6.7.
If prints all rows expanded.
If set to 0, only actually expanded rows prints their children.
Since 6.7 it can be changed via print menu and is saved to cookies.
<Cfg> bool PrintFiltered [0] Saved to cookies, to not load it, set PrintLap=’1’ new 6.7.
If prints all rows, including the hidden.
It can be changed via print menu and is saved to cookies.
<Cfg> bool PrintPageBreaks [0] Saved to cookies, to not load it, set PrintLap=’1’ renamed 6.0;upd 6.7.
Prints page break after every PrintRows variable rows.
For every page it prints new table with all fixed and space rows that have CanPrint=’2’
Since 6.7 it can be changed via print menu and is saved to cookies.
<Cfg> int PrintCols [0] new 6.0;upd 6.7.
If and which menu will be shown before printing.
0 – no menu
1 – menu with columns to select which columns will be printed. Only columns with CanPrint=’1’ are listed.
2 – (new 6.7) menu with column and also with printing options
<Cfg> bool PrintCheckboxes [0] new 6.7 .
For 1 it prints all checkboxes and radio buttons as standard HTML checkbox and radio button inputs instead of style images.
Useful when expected printing without background images.
<Cfg> bool PrintIcons [1] new 7.1 .
For 0 it does not print cell side icons Calendar, Enum and Defaults. It still prints Sort, Filter, Expand and custom icons.
<Cfg> int PrintRows [50] Saved to cookies, to not load it, set PrintLap=’1’ upd 6.7.
For how many rows will be displayed and updated progress bar. Displaying progress bar suppresses also message about slow script. 0 never shows progress bar.
Too small value can slow down the printing.
It is used also as page length for PrintPageBreaks.
Since 6.7 it can be changed via print menu and is saved to cookies.
<Cfg> bool PrintLoad [0] new 7.1.
Set to 1 in server paging or child paging to download all rows to be printed.
Be careful permitting this option, it will download all pages and optionally child pages, when set PrintExpanded.
The count of rows is not known, so the progress dialog does not show correct values except set PrintCount.
<Cfg> int PrintCount new 7.1.
Expected count of rows to print to show it in progress dialog.
Usable especially when set PrintLoad = 1.
Can be set dynamically in OnPrintInit API event.
<Cfg> string PrintPrefix .
HTML code added in front of TreeGrid when printing
<Cfg> string PrintPostfix .
HTML code added behind TreeGrid when printing
<Cfg> string PrintHead new 7.1 .
HTML code added into the print page <head> tag. Useful for adding meta tags to the page.
Only for PrintLocation = 0 or 1
<Cfg> string PrintCSS .
Url of CSS style sheet for printing used instead of default CSS style sheet
Only for PrintLocation = 0 or 1
<Cfg> string PrintWindowProp .
Properties of printing window (the third attribute to window.open)
Only for PrintLocation = 0
API event bool OnPrintStart (TGrid grid) new 6.0 .
Called before the print report is generated.
Return true to cancel printing.
API event void OnPrintInit (TGrid grid, string[id] Cols) new 7.1 .
Called after users selected columns to print and before the print report is generated.
The Cols object contains properties as all column names, the columns selected to print are set to 1, otherwise to 0.
It is possible to modify this array. It is null when set PrintCols = 0.
Other settings like rows per page are already set and can be modified in the grid
Here is possible to modify also PrintCount attribute when printing in server paging.
API event string OnPrint (TGrid grid, Window window, string report) chg 6.0 .
Called after the print report has been generated, but before it was written to the print window and printed
Return true to cancel printing or own print.
Or return new or updated report to print.
window is new window created for printing and should be closed when OnPrint returns true.
report is the generated grid HTML that will be printed.
API event bool OnPrintFinish (TGrid grid, Window window) .
Called after print report is written to the window and before the printing dialog is displayed.
window is browser’s window that contains the report.
You can also use this event to get back changes you done in OnPrintStart event, if any.
Return true to suppress default action. You can call here window.print() in this event and do some action after, for example to close the window.
API event void OnPrintClose (TGrid grid, Window window) new 7.1 .
Called when the print window is being closed or the print report is to be deleted and the original grid restored (depends on PrintLocation settings).
window is browser’s window that contains the report.
Here you can take back changes you done in page in OnPrintFinish, especially for PrintLocation >= 2
API method string GetPrintable (function func) chg 6.0 .
Generates print report for the grid.
If func is not set, it generates the report synchronously without displaying message and returns the generated report.
If func is set, it generates the report asynchronously, shows and updates progress message and after finish calls func (report).
<Actions> Print Attached to event OnClickButtonPrint .
Shows printable version or grid and displays dialog for printing
global func. TGrid PrintTreeGrid (object Source, string tag = “”, string id = “”) new 6.7;upd 7.0 .
Creates and renders new grid by API according to settings in Source.
It renders inactive grid for printing purposes, especially when printing to PDF.
It prints the grid synchronously, without scrollbars, loads also all pages and child pages in server paging, so it can be very slow for long grids.
For long grids and routines that use IE for exporting to PDF it can be useful to disable slow script message in IE by:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles\MaxScriptStatements = 0xFFFFFFFF
Its attributes and other behavior is similar to TreeGrid method.
Source can be:
a) string with <treegrid> or <bdo> tag with all settings like it is included directly to HTML
Example: TreeGrid(“<treegrid Data_Url=’Grid2.xml’></treegrid>”,”Main”);
b) string with XML to create the grid from. The grid will have only Data_Data source defined.
Example: TreeGrid(“<Grid><Cols><C Name=’A’/></Cols><Body><B><I A=’xxx’/></B></Body></Grid>”,”Main”);
c) object with parsed <treegrid> / <bdo> tag.
All multilevel attributes (data sources) containing ‘_’ must be set as nested objects, split by the ‘_’,
for example Data_Param_Test is accessed as Source.Data.Param.Test and set as {Data:{Param:{Test:’val’}}}
Eample: PrintTreeGrid({Layout:{Url:”Grid2Def.xml”},Data:{Url:”Grid2.xml”}},”Main”);
tag is the main div tag to render grid into. The tag can be an id of the tag or the HTMLElement itself. The htm tag must exist in time of calling the function.
If the parameter is missing, the id of the tag must be set in input XML by attribute <Cfg Tag/>. See <treegrid> tag description.
id is the unique id of the grid, used to identify it, especially in saving configuration to the cookies.
If the parameter is missing, the id of the grid can be set in input XML by attribute <Cfg id/>
The function returns created TGrid object.
It returns null for fatal error. It fails if the Source is null or cannot be used as one of the three options.
The Source is accessible by API by grid.Source attribute.
It calls all loading events like OnLoaded or OnReady.
(Since 7.0) It calls also OnRenderStart event, when all data are loaded, even for server paging and OnRenderFinish when the grid is fully rendered (even for paging).