The Report Builder structure is as follows:
+- Report Builder Container
|
+- Report Builder (DocType 1)
| |
| +- DataTable (Output grid)
|
+- Report Bulder (DocType 2)
|
..
..
Reports with selected columns and filters can be saved by clicking on the “Save” link on the top bar of the Report Builder. The report is saved in a record called Search Criteria. Client-side and server-side scripts can be plugged in by using the Search Criteria.
Customizing of filters is done by declaring the report.customize_filters method in the client side of the Search Critiera.
Custom properties of filter fields are
Example:
report.customize_filters = function() {
// hide exiting filters
this.hide_all_filters();
// add a new filter
this.add_filter({fieldname:'show_group_balance', label:'Show Group Balance', fieldtype:'Select', options:NEWLINE+'Yes'+NEWLINE+'No',ignore : 1, parent:'Account'});
// show a filter
this.set_filter_properties('Account','Company',{filter_hide: 0});
// remove limts - show all records
this.dt.set_no_limit(1);
// hide tabs
$dh(this.mytabs.tabs['Select Columns'])
}
The query can be scrubbed on the server side in Python before it. The result data is available as a list-in-a-list res. The output can be modified by updating res or declaring a new list-in-a-list out
Standard lists, dictionary that can be updated
Example - adding a column:
colnames.append('Total')
coltypes.append('Currency')
colwidths.append('120px')
coloptions.append('')
# set the index
col_idx[c[0]] = len(colnames)-1
Example - adding the column data:
sum = 0
for r in res:
# get the total as sum of 2 columns
t = r[col_idx['Val 1']] + r[col_idx['Val 2']]
sum += t
# add it to the record
r.push(t)
Example - getting value from a filter:
if filter_values.get('Show sum')=='Yes':
res.append(['','','', sum])
Style can be set on a row by declaring the beforerowprint method in the Client Script of the Search Criteria Example:
// Example 1: set foreground
report.beforerowprint = function(row){
if(row.data[‘Amount’] > 20000) {
row.style.color = ‘GREEN’;
}
}
// Example 2: set background
report.beforerowprint = function(row){
if(row.data[‘Amount’] < 1000) {
row.style.backgroundColor = ‘#FDD’;
}
}
A query can be generated from a script from the client side like in Listing by declaring the get_query method. Note: Do not put ORDER BY and LIMIT as they would be appended by the Report Builder. There are 2 useful lists
- report.selected_fields - list of selected fields in Table_Name.`field_name` format
- report.filter_vals - dictionary of filter keys and values
Example:
report.get_query = function() {
var query = 'SELECT ' + report.selected_fields.join(', ') + 'FROM `tab..` WHERE ...';
return query;
}
The Report Builder Container is the object that contains ReportBuilder objects for each DocType. This object is managed automatically by the Framework
TabbedPage object representing the tabs of the Report Builder. This can be used to hide / show tabs from the Client Script in the report like:
$dh(this.mytabs.tabs['Select Columns'])
The datatable class represents a grid object to show the results with paging etc
Add a new field for sorting selection - value is the tablename.fieldname for the “ORDER BY” clause:
report.dt.add_sort_option('ID','`tabMyDT`.`name`');