Skip to content

Commit

Permalink
feat: Add chunk rendering feature with a demo
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Jun 26, 2019
1 parent 66b8f24 commit 4e52454
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 318 deletions.
29 changes: 20 additions & 9 deletions BBjGridExWidget.bbj
Expand Up @@ -405,6 +405,13 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
rem */
field public static BBjNumber Debug = 0
rem /**
rem * When true , the grid will render the UI on the client as soon as possible , put it in the loading state
rem * then send the data. once the data is sent and rendered , the grid will remove the loading state automatically.
rem *
rem * Use this mode if you have a large set of data(rows) which sending them to the client will take some time.
rem */
field public BBjNumber ChunkRendering! = 0
rem /**
rem * The grid languages manager
rem */
field protected BBjGridExWidgetLanguageManager LanguageManager! = new BBjGridExWidgetLanguageManager()
Expand Down Expand Up @@ -1442,14 +1449,18 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
REM if(!#IsReady!) then
REM methodret
REM fi
if rs! <> NULL() AND rs!.size() > 0 then
methodret null()
FI

gson! = new Gson()
data$ = #getRS().toJson(1 , #getRowNodeId())

options! = #getAsJsonObject()
#executeScript("gw_setData(" + data$ + "," + gson!.toJson(options!) + ",'" + #LicenseKey$ + "')")
data$ = #getRS().toJson(1 , #getRowNodeId())

if(#getChunkRendering() = 0) then
#executeScript("gw_init(" + options!.toString() + ",'" + #LicenseKey$ + "'," + data$ + ")")
else
#executeScript("gw_init(" + options!.toString() + ",'" + #LicenseKey$ + "')")
if(#getRS() <> null() AND #getRS().size() > 0) then
#executeScript("gw_setRowsData('" + #GRIDID$ + "'," + data$+ ")")
fi
fi
methodend
rem /**
rem * Build the column defintions from the passed resultset
Expand Down Expand Up @@ -1566,7 +1577,7 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
#RS! = rs!

if rs! <> NULL() AND rs!.size() > 0 then
#RS!.createIndex()
#RS!.createIndex(err=*next)
data$=#RS!.toJson(BBjAPI.TRUE,#getRowNodeId())
#executeScript("gw_setRowsData('" + #GRIDID$ + "'," + data$+ ")")
FI
Expand Down Expand Up @@ -1645,7 +1656,7 @@ class public BBjGridExWidget extends BBjWidget implements BBjGridExWidgetColumns
rem */
method public void clearRowsData()
#RS! = new ResultSet()
#RS!.createIndex()
#RS!.createIndex(err=*next)
#executeScript("gw_setRowsData('" + #GRIDID$ + "', [])")
methodend
rem /**
Expand Down
93 changes: 93 additions & 0 deletions ChunkRenderingDemo.bbj
@@ -0,0 +1,93 @@
rem /**
rem * This file is part of the BBjGridExWidget plugin.
rem * (c) Basis Europe <eu@basis.com>
rem *
rem * For the full copyright and license information, please view the LICENSE
rem * file that was distributed with this source code.
rem */
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.db.ResultSet
use com.basiscomponents.bc.SqlQueryBC

? 'HIDE'

declare auto BBjTopLevelWindow wnd!
declare BBjGridExWidget grid!
declare SqlQueryBC sbc!
declare ResultSet rs!

sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))

wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,800,600,"Chunk Rendering Demo")
wnd!.setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd!.setCallback(BBjAPI.ON_RESIZE,"resize")

REM init the grid
grid! = new BBjGridExWidget(wnd!,100,0,0,800,600)
rem /**
rem * We enable the grid chunk rendering mode.
rem *
rem * When this mode is enabled , the grid will send the data in chunks. This is done be sending the column defintions
rem * to the client as soon as possible to get fast first render then it sends the data to fill the grid
rem *
rem * This mode is usefull when you have a large set of data which sending them to the client will take time.
rem */
grid!.setChunkRendering(1)

gosub renderColumns
rem create timer so we can go into process_events
BBjAPI().createTimer("renderColumns" , 1 , "fillGrid")
process_events

renderColumns:
rs! = sbc!.retrieve("SELECT TOP 1 * FROM CDINVENTORY")
REM build the columns from the passed ResultSet
grid!.buildColumnsFromResultSet(rs!,1)
REM just render the grid empty
grid!.render()
return

fillGrid:
rem remove timer as we do not need it anymore
BBjAPI().removeTimer("renderColumns")

rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY")
rem wait some time to simulate a long process
wait 3
grid!.setData(rs!)
return

rem /**
rem * Retrive the data from the database and configure the grid
rem *
rem * The grid!.setData(ResultSet) method will read all columns from the passed ResultSet and create the columns
rem * for you. This method respects the column types defined in the ResultSet and it will make sure that all the created
rem * columns have the correct components attached (filters , cell renderers , ...).
rem * The method will also respects already defined columns and make sure to update them with columns meta fetched from
rem * the ResultSet.
rem *
rem * By default the method will render the grid direcly after setting the data. You can change this and delay the rendering
rem * (for example to configure the columns) by passing a second paramter to the method grid!.setData(ResultSet , 0)
rem * and then call grid!.render().
rem */
main:
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY")
grid!.setData(rs!)
return

rem /**
rem * Listen to the BBjTopLevelWindow resize events and
rem * resize the grid to fill the available space.
rem */
resize:
ev! = BBjAPI().getLastEvent()
w=ev!.getWidth()
h=ev!.getHeight()
grid!.setSize(w,h)
return

rem /**
rem * Close the demo
rem */
byebye:
bye

0 comments on commit 4e52454

Please sign in to comment.