Skip to content

Commit

Permalink
Implement client data update
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Jul 3, 2018
1 parent c75b890 commit 944d0cd
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 7 deletions.
88 changes: 86 additions & 2 deletions BBjGridExWidget.bbj
Expand Up @@ -154,7 +154,7 @@ class public BBjGridExWidget extends BBjWidget
rem */
field public BBjString GroupColumnLabel$ = "Group"
rem /**
rem * Set the default grouping footer getter expression
rem * Set the default grouping footer getter expression
rem *
rem * @RequiresRefresh
rem */
Expand Down Expand Up @@ -367,7 +367,7 @@ class public BBjGridExWidget extends BBjWidget
field private ResultSet RS!
field private BBjString URL$
field private DataTree TREE!
field private BBjString RowNodeId$
field private BBjString RowNodeId$ = "__ROW_INDEX"
field private BBjString ParentNodeId$
field private DataRow ColumnDefinition!
field public DataRow AttributesRecord!
Expand Down Expand Up @@ -582,6 +582,90 @@ class public BBjGridExWidget extends BBjWidget
#setData(rs! , RowNodeId$)
methodend
rem /**
rem * Set new rows into the grid
rem *
rem * @param ResultSet: the com.basiscomponents.db.ResultSet with the data
rem */
method public void setRowsData(ResultSet rs!)
#RS! = rs!

if #AttributesRecord! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
rem TODO: use the new method of components as soon as implemented
rem https://github.com/BasisHub/components/issues/87
r1! = rs!.getItem(0)
ar! = #AttributesRecord!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()

if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi

if #ColumnDefinition! <> NULL() AND rs! <> NULL() AND rs!.size() >0 then
r1! = rs!.getItem(0)
ar! = #ColumnDefinition!
it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()

if ar!.contains(f$) then
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
fi
wend
fi

#TREE! = null()
#URL$=""
#SelectedRowsMap!.clear()

if com.basiscomponents.VersionInfo.getComponentsBuildTimeMillis() > 1529907740051 then
data$=#RS!.toJson(BBjAPI.TRUE,"__ROW_INDEX")
else
data$=#RS!.toJson(BBjAPI.TRUE)
fi

#executeScript("gw_setRowsData(" + data$+ ")")
methodend
rem /**
rem * Clear row data (Empty the grid )
rem */
method public void clearRowsData()
#RS! = new ResultSet()
#TREE! = null()
#URL$=""
#SelectedRowsMap!.clear()
#executeScript("gw_setRowsData([])")
methodend
rem /**
rem * Update row data
rem *
rem * @param BBjNumber: row index
rem * @param DataRow: DataRow object which contains the update
rem */
method public void setRowData(BBjNumber index!,DataRow row!)
if #RS!.count() <> 0 then
#RS!.setItem(index!,row!)
row!.setFieldValue("__ROW_INDEX",str(index!))
#executeScript("gw_setRowData(" + row!.toJson() +")")
fi
methodend
rem /**
rem * Remove row from grid by index
rem *
rem * @param BBjNumber: row index
rem */
method public void removeRow(BBjNumber index!)
if #RS!.count() <> 0 then
#RS!.remove(index!)
#executeScript("gw_removeRow(" + str(index!) +")")
rem print #RS!.getItem(index!)
rem escape
fi
methodend
rem /**
rem * add a column to the grid
rem * @param BBjString field$: the field name that matches the ResultSet
rem * @param BBjString label$: the column header
Expand Down
103 changes: 103 additions & 0 deletions Demo/DataUpdateDemo.bbj
@@ -0,0 +1,103 @@
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.bc.SqlQueryBC
use java.sql.Types

? 'HIDE'

declare auto BBjTopLevelWindow wnd!
declare auto BBjListButton lb_db!
declare auto BBjListButton lb_tbl!
declare auto BBjToolButton btn_fit!
declare BBjGridExWidget grid!

x=0
y=0
w=800
h=600

wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,800,600,"BBj Grid Ex Demo")
grid! = new BBjGridExWidget(wnd!,100,x,y,w,h-50)
wnd! .setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd! .setCallback(BBjAPI.ON_RESIZE,"resize")

grid!.setCallback(grid!.ON_GRID_SELECT_ROW(),"onRowSelect")

restoreOrginial! = wnd!.addButton(200,10,h-38,150,25,"Restore Original ResultSet")
restoreOrginial!.setCallback(BBjAPI.ON_BUTTON_PUSH,"restoreOrginialRS")

updateResultSet! = wnd!.addButton(201,160,h-38,150,25,"Set New ResultSet")
updateResultSet!.setCallback(BBjAPI.ON_BUTTON_PUSH,"setNewRS")

updateFirstRow! = wnd!.addButton(202,310,h-38,100,25,"Update First Row")
updateFirstRow!.setCallback(BBjAPI.ON_BUTTON_PUSH,"updateFirstRow")

removeFirstRow! = wnd!.addButton(203,410,h-38,100,25,"Remove First Row")
removeFirstRow!.setCallback(BBjAPI.ON_BUTTON_PUSH,"removeFirstRow")

clearRowsData! = wnd!.addButton(204,510,h-38,100,25,"Clear Rows")
clearRowsData!.setCallback(BBjAPI.ON_BUTTON_PUSH,"clearRowsData")

gosub fillGrid

process_events

fillGrid:
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY ")
grid!.setData(rs!,"CDNUMBER")
return

restoreOrginialRS:
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY ")
grid!.setRowsData(rs!)
return

setNewRS:
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT TOP 5 * FROM CDINVENTORY ")
grid!.setRowsData(rs!)
return

updateFirstRow:
row! = rs!.getItem(0)
row!.setFieldValue("TITLE","My New Title")
row!.setFieldValue("ARTIST","My New ARTIST")
grid!.setRowData(0 , row!)
return

removeFirstRow:
grid!.removeRow(0)
return

clearRowsData:
grid!.clearRowsData()
return

onRowSelect:
ev! = BBjAPI().getLastEvent()
ev! = ev!.getObject()

sel! = grid!.getSelectedRows()

if INFO(3,6)="5" then
a = msgbox(ev!.getNewSelectedRows().toString(), 0, "Selection")
else
print 'SHOW',
print ev!.getRowCount(), " ROW(s) AFFECTED By Event:" , ev!.getChangedRows()
print ev!.getSelectedRowCount()," ROW(S) SELECTED By Event: ",ev!.getNewSelectedRows()
print ev!.getDeselectedRowCount()," ROW(S) DESELECTED By Event: ",ev!.getNewDeselectedRows()
print ev!.getSelectedRows().size()," ROW(S) NOW SELECTED : ", ev!.getSelectedRows()
print "------------------------------------------------------------------------"
fi
return

resize:
ev! = BBjAPI().getLastEvent()
w=ev!.getWidth()
h=ev!.getHeight()
grid!.setSize(w,h-80)
return

byebye:
bye
6 changes: 3 additions & 3 deletions js/dist/bbj-grid-widget.min.js

Large diffs are not rendered by default.

0 comments on commit 944d0cd

Please sign in to comment.