Skip to content

Commit

Permalink
feat: Add the ability to set the row height globally and by row (#112)
Browse files Browse the repository at this point in the history
feat: Add the ability to set the row height globally and by row

See #110

Fixes #110
  • Loading branch information
hyyan committed Mar 19, 2019
1 parent 45695cc commit 90d4771
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 3 deletions.
25 changes: 25 additions & 0 deletions BBjGridExWidget.bbj
Expand Up @@ -298,6 +298,12 @@ class public BBjGridExWidget extends BBjWidget
rem */
field public BBjGridContextMenu ContextMenu! = new BBjGridDefaultContextMenu()
rem /**
rem * The grid default row height
rem *
rem * @RequiresRefresh
rem */
field public BBjNumber RowHeight! = 25
rem /**
rem * The grid sidebar
rem *
rem * Set the default grid sidebar
Expand Down Expand Up @@ -1104,6 +1110,24 @@ class public BBjGridExWidget extends BBjWidget
FI
methodend
rem /**
rem * Set all rows height
rem *
rem * @param BBjNumber height! - the new row height
rem */
method public void setRowHeight (BBjNumber height!)
#RowHeight! = height!
#executeScript("gw_setRowsHeight('" + #GRIDID$ + "'," + str(height!) + ")")
methodend
rem /**
rem * Set the given row height
rem *
rem * @param BBjNumber index! - the row index
rem * @param BBjNumber height! - the new row height
rem */
method public void setRowHeight (BBjNumber index!, BBjNumber height!)
#executeScript("gw_setRowHeight('" + #GRIDID$ + "'," + str(index!) + "," + str(height!) + ")")
methodend
rem /**
rem * set the width of a column
rem *
rem * @param BBjString Field$: the field name of the column
Expand Down Expand Up @@ -1763,6 +1787,7 @@ class public BBjGridExWidget extends BBjWidget
options!.addProperty("groupUseEntireRow",#GroupUseEntireRow!)
options!.addProperty("groupIncludeFooter",#GroupIncludeFooter!)
options!.addProperty("groupIncludeTotalFooter",#GroupIncludeTotalFooter!)
options!.addProperty("rowHeight",#RowHeight!.longValue())
options!.addProperty("sideBar",#Sidebar!.toString())
autoGroupColumnDef! = new JsonObject()

Expand Down
10 changes: 10 additions & 0 deletions Demo/Demo.bbj
Expand Up @@ -153,4 +153,14 @@ setTheme:
ev! = BBjAPI().getLastEvent()
theme$ = ev!.getSelectedItem()
grid!.setTheme(theme$)
if theme$="material" then
grid!.setRowHeight(50)
else
grid!.setRowHeight(25)
fi

if theme$="balham-dark"
grid!.setRowHeight(0,50)
fi

return
39 changes: 38 additions & 1 deletion js/dist/bbj-grid-widget.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/bbj-grid-widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions js/src/api/rows.js
Expand Up @@ -118,3 +118,37 @@ export function gw_addRows(id, index, rows) {
options.api.updateRowData({ add: rows, addIndex: index });
options.api.refreshClientSideRowModel('group');
}

/**
* Set the height of all rows
*
* @param {String} id the grid id
* @param {Number} height the row height
*/
export function gw_setRowsHeight(id, height) {
const options = gw_getGrid(id).options;

options.api.forEachNode(row => {
row.setRowHeight(height);
});
options.api.onRowHeightChanged()
}

/**
* Set the given row height
*
* @param {String} id the grid id
* @param {Number} index the row index
* @param {Number} height the new height
*/
export function gw_setRowHeight(id, index, height) {
const options = gw_getGrid(id).options;
const row = options.api.getDisplayedRowAtIndex(index);

if (row) {
row.setRowHeight(height);
options.api.onRowHeightChanged()
} else {
console.warn(`Failed to set height for row ${index}. Row can not be found`);
}
}

0 comments on commit 90d4771

Please sign in to comment.