Gridx in XPages – 11: Grid API Methods

Gridx has a number of handy API methods for working with the grid, rows, and columns. In this post, I’ll show a number of examples for how to start working with the grid programmatically.

Gridx Series

Gridx in XPages — Entire Series

Sample Grid

All of the examples will be based on a grid that shows this output:

Gridx 11 - Sample

Grid

Here are some examples of basic grid API calls:

Code Purpose Result
grid.columnCount(); # Columns 3
grid.rowCount(); # Rows 1301
grid.cell(2,1).data(); Data in the cell in the 3rd row, 2nd column Ainsworth

The grid also has setColumns() and setStore() methods, in case you want to change the structure or data dynamically.

Column

Columns can be referenced by index (0-based) or by name.

Here are some examples of grid column API calls:

Code Purpose Result
grid.column(0).name(); Name of the 1st column First
grid.column(0).field(); Field name of 1st column firstname
grid.column(1).getWidth(); Current width of 2nd column 146px
grid.column(‘last’).getWidth(); Current width of column named ‘last’ 146px
grid.column(‘last’).index(); Index of column named ‘last’ 1
grid.column(‘last’).cells(2, 2); Returns cell objects based on starting row and number of cells specified. Array of 2 cell objects in the ‘last’ column, starting with the 3rd row

Row

Here are some examples of basic grid row API calls:

Code Purpose Result
grid.row(3).id; Row ID of the 4th row 1CC6
grid.row(‘1CC6’).index(); Index of the row with ID ‘1CC6’ 3
grid.row(3).cells(); Array of cells in the 4th row Array of cell objects
grid.row(3).data(); Object containing the data in the 4th row {first=”Adrienne”, last=”Hall”, state=”FL”}
grid.row(3).item(); Object containing the data in the underlying data store item

The data() method includes the elements displayed in the grid. The item() method includes all attributes of the underlying data store (e.g. all of the attributes provided by the REST service).

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: