Grid: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 34: Line 34:
| cols || The number of columns in the table. (Design time only)  
| cols || The number of columns in the table. (Design time only)  
|-
|-
| colwidths || The width of each column, in pixels (100px), comma separated. Read only at runtime.
| colwidths || The width of each column, in pixels (100px), comma separated. Design time only.
|-
|-
| deleteCols(''n'') || Deletes ''n'' columns from the right of the table. Default is 1.
| deleteCols(''n'') || Deletes ''n'' columns from the right of the table. Default is 1.

Revision as of 09:08, 30 July 2012

Description

The Grid control is used to display data in a table. To add a Grid to your app, choose the Grid icon in the Toolbar. Use the Property Editor to set the properties.

The onclick event can be used to check for clicks. Check event.target.id to find out which cell was clicked.

The width of the grid is set to the total of the pixel widths of the columns, if supplied. Otherwise, it is full width.

If you set the style of the grid to ‘table-layout:fixed;’ it will force the able to maintain cell widths. If the data is too big, it will overflow to the next cell, as in Excel.

If you change the size of a control with scrolling enabled at runtime (by doing addCols or deleteRows, etc.), you need to recalulate the size of the scrolling area by doing controlname.refresh(). This also applies if you load a new form with a Grid on it: the width also needs to be set:

 Grid1.refresh()

To add a control to your app, choose the control’s icon in the Toolbar, then position it on the Design Screen. Use the Property Editor to set the properties you need, then add functions to your code to respond to the events that come from the control: usually, just onclick.

Properties and Methods

Standard properties are supported), plus:

addCols(n) Add n columns to the right of the table. Default is 1.
addRows(n) Adds n rows to the end of the table. Default is 1.
alignments The alignment of the data in each column. Can be left, right, center, justify or char=”.”. Optional. (Design time only)
cell(row, col) Returns a reference to cell x,y.
cellstyle The style of each cell in the grid. Use cell(x,y).style at runtime.
cols The number of columns in the table. (Design time only)
colwidths The width of each column, in pixels (100px), comma separated. Design time only.
deleteCols(n) Deletes n columns from the right of the table. Default is 1.
deleteRows(n) Delete n rows from the end of the table. Default is 1.
getColCount() Returns the number of columns.
getRowCount() Returns the number of rows.
getValue(row,col) Get the current value of a cell.
rowheights The height of each row, in pixels (20px) or percentages (20%), comma separated. Read only at runtime.
refresh() Recalculate the scrolling area after additions or deletions.
rows The number of rows in the table. (Design time only)
scroll_options This control makes use of iScroll. It has a number of options, including:

bounce: true/false. When the end of the scroll area is reached, should the image bounce?

zoom: true/false. Allow two finger zoom in gesture?

The full list of options is documented here: http://cubiq.org/iscroll-4

scrollHeight The size of the scrolling area. (design time)
scrolling Allow choices in the menu to scoll? On or off. (design time)
setColumnWidth(col, width) Sets the width of col to width.
setRowHeight(row, height) Sets the height of row to height.
setValue(row, col, value) Set the value of a cell. Can be string or HTML.
titles The titles for each column, comma separated. Optional. (Design time only)

Events

Grid supports the standard events.

Example

For row=0 to 3
  For col=0 to 3
    Grid1.setValue(row,col,row*col)
  Next
Next
 
Function Button1_onclick()
  MsgBox "Grid(3,3)=" & Grid1.getValue(3,3)
End Function
 
Function Grid1_onclick()
  s=Split(event.target.id, "_")
  MsgBox "Click on " & s(0) & " at row " & s(1) & " and column " & s(2)
  MsgBox "Value is " & Grid1.getValue(s(1),s(2))
 
End Function

Output