Skip to content

Commit

Permalink
feat: extend setSelectedRow(s) methods to allow selection by key
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Mar 6, 2020
1 parent a7a13c4 commit 2153a4e
Show file tree
Hide file tree
Showing 6 changed files with 28,933 additions and 23 deletions.
27 changes: 19 additions & 8 deletions BBjGridExWidget.bbj
Expand Up @@ -2047,22 +2047,33 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
#executeScript(script$)
methodend
rem /**
rem * Select a row
rem * Select a row by its key
rem *
rem * <br><b><small>#API</small></b>
rem *
rem * @param BBJNumber x!: the row index to select
rem * @param BBjString x!: the row key to select
rem */
method public void setSelectedRow(BBjNumber x!)
script$="$wnd.gw_setSelectedRows('" + #GRIDID$ + "',[" + str(x!) + "]);"
method public void setSelectedRow(BBjString key!)
script$="$wnd.gw_setSelectedRows('" + #GRIDID$ + "',['" + str(key!) + "']);"
#executeScript(script$)
methodend
methodend
rem /**
rem * Select a row by its index
rem *
rem * <br><b><small>#API</small></b>
rem *
rem * @param BBjNumber x!: the row index to select
rem */
method public void setSelectedRow(BBjNumber index!)
#setSelectedRow(str(index!))
methodend
rem /**
rem * Select verctor of rows
rem * Select verctor of rows.
rem * The vector can contain a mix of row indices and row keys
rem *
rem * <br><b><small>#API</small></b>
rem *
rem * @param BBJNumber x!: vector of row indices to select
rem * @param BBJNumber x!: vector of row indices and row keys to select
rem */
method public void setSelectedRows(BBjVector x!)
script$="$wnd.gw_setSelectedRows('" + #GRIDID$ + "',["
Expand All @@ -2075,7 +2086,7 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
script$=script$+","
FI

script$=script$+str(it!.next())
script$ = script$ + "'" + str(it!.next()) + "'"
wend

script$=script$+"]);"
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# A Grid Widget Plugin for BBj
<p>
<a href="http://www.basis.com/downloads">
<img src="https://img.shields.io/badge/BBj-v18.21-blue" alt="BBj v18.11" />
<img src="https://img.shields.io/badge/BBj-v19.11-blue" alt="BBj v19.11" />
</a>
<a href="http://www.basis.com/downloads">
<img src="https://img.shields.io/badge/BBj-SAM%20required-orange" alt="BBj sam required" />
Expand Down
28,190 changes: 28,184 additions & 6 deletions client/dist/bbj-grid-widget.js

Large diffs are not rendered by default.

715 changes: 712 additions & 3 deletions client/dist/bbj-grid-widget.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/report.html

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions client/src/api/rows.js
Expand Up @@ -32,7 +32,7 @@ export function gw_collapseAll(id) {
export function gw_ensureIndexVisible(id, index, position) {
const api = gw_getGrid(id).options.api;
const node = api.getRowNode(index);

api.ensureIndexVisible(node ? node.rowIndex : Number(index), position);
}

Expand Down Expand Up @@ -170,16 +170,28 @@ export function gw_setRowHeight(id, index, height) {
}
}

/**
* Select row or more based on the row id or index
*
* @param {String} id the grid's id
* @param {Array} rows an array of row keys and indexes to select
*/
export function gw_setSelectedRows(id, rows) {
console.log(id, rows);
const options = gw_getGrid(id).options;
const api = options.api;

options.api.forEachNodeAfterFilterAndSort(node => {
if (rows.indexOf(node.rowIndex) > -1) {
api.forEachNodeAfterFilterAndSort(node => {
if (
rows.indexOf(String(node.rowIndex)) > -1 ||
rows.indexOf(String(node.id)) > -1
) {
node.setSelected(true);
node.expanded = true;
}
});
options.api.onGroupExpandedOrCollapsed();

api.onGroupExpandedOrCollapsed();
}

export function gw_selectAll(id, filtered) {
Expand Down

0 comments on commit 2153a4e

Please sign in to comment.