I. Overview
1.1 Requirement
In some cases, we need to select a batch of records and then modify values in a column all at once. For example, batch approval or batch cancellation of approval is often required for selected records, as it takes more time and energy to click the Approval button for each row. Such batch operations can be enabled in reports via JavaScript, with the effect shown below:
1.2 Solution
Traverse checkboxes through JavaScript, judge whether they are checked, fetch checked row numbers and then use contentPane.setCellValue(col,row,value) for batch setting.
II. Sample
2.1 Add Button widgets
Add Button widgets named ‘Terminate the order’ and ‘Cancel termination order’ to D1 and F1 respectively, as shown below in D1:
2.2 Add an After Initialization event
Add an After Initialization event to the Checkbox widget in A3, as shown below:
Input the following JavaScript codes:
if (!window.lineboxes) {
window.lineboxes = [];
}
lineboxes[lineboxes.length] = this;
2.3 Add a click event
Add a click event to the button in D1, as shown below:
Input the following JavaScript codes:
if (window.lineboxes) {
var cells = [];
for (var i = 0; i < lineboxes.length; i++) {
if (lineboxes[i].selected()) {
var cr = FR.cellStr2ColumnRow(window.lineboxes[i].options.location);
//Fetch the rows and columns in which checked checkboxes are located
_g().setCellValue(7, cr.row, 'N');
//Assign values to these rows and columns one by one; here, 7 is a column number and means column H
}
}
}
Add a click event to the button in D1 by inputting the following JavaScript codes:
if (window.lineboxes) {
var cells = [];
for (var i = 0; i < lineboxes.length; i++) {
if (lineboxes[i].selected()) {
var cr = FR.cellStr2ColumnRow(window.lineboxes[i].options.location);
//Fetch the rows and columns in which checked checkboxes are located
_g().setCellValue(7, cr.row, 'Y');
//Assign values to these rows and columns one by one; here, 7 is a column number and means column H
}
}
}
2.4 Preview
Save the template and click [Data Entry Preview]. The effect is shown below: