Creating a Rico LiveGrid
View this page in Japanese
Rico LiveGrid displays data in a scrolling table, with the data buffered in a
2-dimensional JavaScript array. As the user scrolls
vertically through the grid, data is dynamically copied from the array onto the grid.
The buffer can can be loaded from:
- a javascript array
- an HTML table
- an XML file
- a SQL database query
- a custom javascript callback function
- Load the data to be displayed into a javascript array.
var myData = [
[1,'Cell 1:2','Cell 1:3','Cell 1:4','Cell 1:5'],
[2,'Cell 2:2','Cell 2:3','Cell 2:4','Cell 2:5'],
[3,'Cell 3:2','Cell 3:3','Cell 3:4','Cell 3:5'],
[4,'Cell 4:2','Cell 4:3','Cell 4:4','Cell 4:5']
];
- Load the Rico javascript and css files necessary to display the grid.
Rico.loadModule('LiveGrid','LiveGridMenu','greenHdg.css');
- LiveGrid
- This loads the Rico javascript and css files necessary to display a LiveGrid
with a static buffer (no AJAX).
- LiveGridMenu
- This loads the default grid menu. This menu provides access to all of the LiveGrid capabilities.
It adjusts the selections presented to the user based on the column selected
and the type of buffer used.
You can also choose to use the grid with no menu at all, or to create your own menu
customized to the needs of your application.
- greenHdg.css
- Rico comes with several sample grid styles: coffee-with-milk,
grayedout, greenHdg, iegradient (Internet Explorer only), tanChisel, and warmfall.
You may choose one of the included styles or create one of your own.
- Load the array into a Rico Buffer object:
var buffer=new Rico.Buffer.Base();
buffer.loadRowsFromArray(myData);
- Define the grid's options, including the grid headings:
var opts = {
useUnformattedColWidth: false,
defaultWidth : 90,
visibleRows : 'data',
frozenColumns: 1,
columnSpecs : [{Hdg:'Column 1',type:'number', ClassName:'alignright'},
{Hdg:'Column 2'},
{Hdg:'Column 3'},
{Hdg:'Column 4'},
{Hdg:'Column 5'}]
};
- Instantiate the LiveGrid, passing in the base id for the grid,
the Rico.Buffer instance, and the grid options.
var ex1=new Rico.LiveGrid ('ex1', buffer, opts);
- To enable the default pop-up menu for the grid, assign the grid's
menu property to an instance of Rico.GridMenu.
ex1.menu=new Rico.GridMenu();
- Rico.loadModule may finish after the window.onload event.
So to ensure that the grid initialization runs after the Rico modules
have loaded, you must pass the initialization function to the
Rico.onLoad method. Putting all of the javascript together would look like this:
<script type='text/javascript'>
Rico.loadModule('LiveGrid','LiveGridMenu','greenHdg.css');
Rico.onLoad( function() {
var myData = [
[1,'Cell 1:2','Cell 1:3','Cell 1:4','Cell 1:5'],
[2,'Cell 2:2','Cell 2:3','Cell 2:4','Cell 2:5'],
[3,'Cell 3:2','Cell 3:3','Cell 3:4','Cell 3:5'],
[4,'Cell 4:2','Cell 4:3','Cell 4:4','Cell 4:5']
];
var opts = {
useUnformattedColWidth: false,
defaultWidth : 90,
visibleRows : 'data',
frozenColumns: 1,
columnSpecs : [{Hdg:'Column 1',type:'number', ClassName:'alignright'},
{Hdg:'Column 2'},
{Hdg:'Column 3'},
{Hdg:'Column 4'},
{Hdg:'Column 5'}]
};
var buffer=new Rico.Buffer.Base();
buffer.loadRowsFromArray(myData);
var ex1=new Rico.LiveGrid ('ex1', buffer, opts);
ex1.menu=new Rico.GridMenu();
});
</script>
- Finally, place a div element in your HTML markup at the position where the grid should go.
Including the markup for the bookmark will cause the grid's scroll position to be displayed.
<p class="ricoBookmark"><span id="ex1_bookmark"> </span></p>
<div id="ex1"></div>
- Define an HTML table with the headings in a
<thead>
section
and the data in a <tbody>
section.
Including the markup for the bookmark will cause the grid's scroll position to be displayed.
<p class="ricoBookmark"><span id="data_grid_bookmark"> </span></p>
<table id="data_grid">
<thead>
<tr>
<th>First column name</th>
<th>Second column name</th>
...
<th>Last column name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, column 1 data</td>
<td>Row 1, column 2 data</td>
...
<td>Row 1, last column data</td>
</tr>
<tr>
<td>Row 2, column 1 data</td>
<td>Row 2, column 2 data</td>
...
<td>Row 2, last column data</td>
</tr>
...
<tr>
<td>Row n, column 1 data</td>
<td>Row n, column 2 data</td>
...
<td>Row n, last column data</td>
</tr>
</tbody>
</table>
- Load the Rico javascript and css files necessary to display the grid.
Rico.loadModule('LiveGrid','LiveGridMenu','greenHdg.css');
- LiveGrid
- This loads the Rico javascript and css files necessary to display a LiveGrid
with a static buffer (no AJAX).
- LiveGridMenu
- This loads the default grid menu. This menu provides access to all of the LiveGrid capabilities.
It adjusts the selections presented to the user based on the column selected
and the type of buffer used.
You can also choose to use the grid with no menu at all, or to create your own menu
customized to the needs of your application.
- greenHdg.css
- Rico comes with several sample grid styles: coffee-with-milk,
grayedout, greenHdg, iegradient (Internet Explorer only), tanChisel, and warmfall.
You may choose one of the included styles or create one of your own.
- Load the table's data rows into a Rico Buffer object:
var buffer = new Rico.Buffer.Base($('data_grid').tBodies[0]);
- Finally, instantiate the LiveGrid, passing in the DOM id of the HTML table
(this allows the LiveGrid to load the column headings from the table's thead section),
the Rico.Buffer instance, and any options (in this case the first column gets
a width of 50 pixels and the second column gets a width of 80 pixels).
var grid_options = { columnSpecs: [ {width:50}, {width:80} ] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
- Rico.loadModule may finish after the window.onload event.
So to ensure that the grid initialization runs after the Rico modules
have loaded, you must pass the initialization function to the
Rico.onLoad method. Putting all of the javascript together would look like this:
<script type='text/javascript'>
Rico.loadModule('LiveGrid','LiveGridMenu','greenHdg.css');
Rico.onLoad( function() {
var buffer = new Rico.Buffer.Base($('data_grid').tBodies[0]);
var grid_options = { columnSpecs: [width:50, width:80] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
});
</script>
- Define an HTML table, supplying the table header cells, but no table body cells.
Including the markup for the bookmark will cause the grid's scroll position to be displayed.
<p class="ricoBookmark"><span id="data_grid_bookmark"> </span></p>
<table id="data_grid">
<tr>
<th>First column name</th>
<th>Second column name</th>
</tr>
</table>
- Load the Rico javascript and css files necessary to display the grid.
Rico.loadModule('LiveGridAjax','LiveGridMenu','greenHdg.css');
- LiveGridAjax
- This loads the Rico javascript and css files necessary to display a LiveGrid
with an AJAX-enabled buffer.
- LiveGridMenu
- This loads the default grid menu. This menu provides access to all of the LiveGrid capabilities.
It adjusts the selections presented to the user based on the column selected
and the type of buffer used.
You can also choose to use the grid with no menu at all, or to create your own menu
customized to the needs of your application.
- greenHdg.css
- Rico comes with several sample grid styles: coffee-with-milk,
grayedout, greenHdg, iegradient (Internet Explorer only), tanChisel, and warmfall.
You may choose one of the included styles or create one of your own.
- Create a Rico Buffer, which fetches data to populate the table.
The AjaxXML buffer makes just one request for data to the supplied URL
at grid startup.
var buffer = new Rico.Buffer.AjaxXML('/controller/action?format=xml');
The URL ("/controller/action?format=xml" in this example) must return data in the following format:
<ajax-response>
<response type='object' id='data_grid_updater'>
<rows update_ui='true' offset='0'>
<tr><td>Data for row 1, cell 1</td><td>Data for row 1, cell 2</td></tr>
<tr><td>Data for row 2, cell 1</td><td>Data for row 2, cell 2</td></tr>
</rows>
</response>
</ajax-response>
- Finally, instantiate the LiveGrid, passing in the DOM id of the HTML table,
the Rico.Buffer instance, and any options (columnSpecs is not required,
but shown here as a placeholder for customization of the columns).
var grid_options = { columnSpecs: [,] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
- Rico.loadModule may finish after the window.onload event.
So to ensure that the grid initialization runs after the Rico modules
have loaded, you must pass the initialization function to the
Rico.onLoad method. Putting all of the javascript together would look like this:
<script type='text/javascript'>
Rico.loadModule('LiveGridAjax','LiveGridMenu','greenHdg.css');
Rico.onLoad( function() {
var buffer = new Rico.Buffer.AjaxXML('/controller/action?format=xml');
var grid_options = { columnSpecs: [,] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
});
</script>
The descriptions below apply directly to the ASP and PHP implementations of the Rico LiveGrid plug-ins.
The concepts are the same in .net, but the implementation is quite different
(examine ex2simple.aspx to see how this gets implemented in .net).
- Define a session variable that contains the query to be run. The variable name must
match the id of the table below. When requesting data, the grid will pass its id
to ricoXMLquery, and ricoXMLquery will use it to get the query text from
the session variable.
- ASP:
<%
session.contents("data_grid")="select ID,Name,City from customers"
%>
- PHP:
<?
$_SESSION['data_grid']="select ID,Name,City from customers";
?>
- .net:
Sub Page_Load(Sender As object, e As EventArgs)
data_grid.sqlQuery="select ID,Name,City from customers"
' session variable is set by the control
End Sub
- Define an HTML table, supplying the table header cells, but no table body cells.
Including the markup for the bookmark will cause the grid's scroll position to be displayed.
<p class="ricoBookmark"><span id="data_grid_bookmark"> </span></p>
<table id="data_grid">
<tr>
<th>Customer #</th>
<th>Customer Name</th>
<th>City</th>
</tr>
</table>
- Load the Rico javascript and css files necessary to display the grid.
Rico.loadModule('LiveGridAjax','LiveGridMenu','greenHdg.css');
- LiveGridAjax
- This loads the Rico javascript and css files necessary to display a LiveGrid
with an AJAX-enabled buffer.
- LiveGridMenu
- This loads the default grid menu. This menu provides access to all of the LiveGrid capabilities.
It adjusts the selections presented to the user based on the column selected
and the type of buffer used.
You can also choose to use the grid with no menu at all, or to create your own menu
customized to the needs of your application.
- greenHdg.css
- Rico comes with several sample grid styles: coffee-with-milk,
grayedout, greenHdg, iegradient (Internet Explorer only), tanChisel, and warmfall.
You may choose one of the included styles or create one of your own.
- Create a Rico Buffer, which fetches data to populate the table.
Unlike the AjaxXML buffer which fetches all grid data at once, the AjaxSQL
buffer fetches data in chunks. This makes it possible for LiveGrid to
efficiently display query results containing thousands, or even hundreds of thousands
of rows.
var buffer = new Rico.Buffer.AjaxSQL('ricoXMLquery.asp');
The URL ("ricoXMLquery.asp" in this example) utilizes one of the included plug-ins to
fetch data from the database and return it to the grid in this XML format:
<ajax-response>
<response type='object' id='data_grid_updater'>
<rows update_ui='true' offset='0'>
<tr><td>Data for row 1, cell 1</td><td>Data for row 1, cell 2</td></tr>
<tr><td>Data for row 2, cell 1</td><td>Data for row 2, cell 2</td></tr>
</rows>
<rowcount>99</rowcount>
</response>
</ajax-response>
The <rowcount> tag is optional, but should be returned whenever the "get_total"
querystring parameter is present in the request.
- Finally, instantiate the LiveGrid, passing in the DOM id of the HTML table,
the Rico.Buffer instance, and any options (columnSpecs is not required,
but shown here as a placeholder for customization of the columns).
var grid_options = { columnSpecs: [,,] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
- Rico.loadModule may finish after the window.onload event.
So to ensure that the grid initialization runs after the Rico modules
have loaded, you must pass the initialization function to the
Rico.onLoad method. Putting all of the javascript together would look like this:
<script type='text/javascript'>
Rico.loadModule('LiveGridAjax','LiveGridMenu','greenHdg.css');
Rico.onLoad( function() {
var buffer = new Rico.Buffer.AjaxSQL('ricoXMLquery.asp');
var grid_options = { columnSpecs: [,,] };
var grid = new Rico.LiveGrid('data_grid', buffer, grid_options);
});
</script>
This model works the same way as models 3 and 4 except that, rather than fetching
data using an xmlHTTPrequest, the data is fetched using javascript callback functions.
This allows you to do creative things in the callback function - like call Google Gears.
Setting up the callback is very easy. Rather than passing a string containing the data provider's URL
to the AjaxXML or AjaxSQL constructor, you just pass the callback function instead.
The code that follows is taken from
examples/client/gridJSbuffer.html,
which uses the AjaxXML buffer. The "jsfetch" callback function
returns a 2-dimensional array that is 100 rows long by 5 columns wide.
Note that AjaxXML only loads its buffer once (at grid startup), so
jsfetch will only be called once.
The options hash is identical in structure to the options hash used
by Prototype's Ajax.Request method.
buffer=new Rico.Buffer.AjaxXML(jsfetch);
function jsfetch(options) {
Rico.writeDebugMsg("jsfetch");
var newRows=[], offset=options.parameters.offset;
for (var r=0; r<100; r++) {
var row=[];
row.push(offset.toString());
row.push(new Date().toString());
for (var c=2; c<5; c++) row.push('cell '+r+':'+c);
newRows.push(row);
}
options.onComplete(newRows);
}
The code that follows is taken from
examples/client/gridJSbuffer2.html,
which uses the AjaxSQL buffer. The "jsfetch" callback function
simulates a 2-dimensional array that is 500 rows long by 5 columns wide.
However, only a section of that array is returned during any one callback --
just the rows from options.parameters.offset
to
options.parameters.offset + options.parameters.page_size
.
buffer=new Rico.Buffer.AjaxSQL(jsfetch);
function jsfetch(options) {
var newRows=[], totrows=500;
var offset=options.parameters.offset;
var limit=Math.min(totrows-offset,options.parameters.page_size)
for (var r=0; r<limit; r++) {
var row=[];
row.push(new Date().toString());
row.push(offset.toString());
for (var c=2; c<5; c++) row.push('cell '+(r+offset)+':'+c);
newRows.push(row);
}
options.onComplete(newRows,false,totrows);
}
options.onComplete takes the following parameters:
- newRows - 2-dimensional array where each item is a string
- newAttr - 2-dimensional array where each item is an object containing acceptAttr values for the cell,
or false if acceptAttr is not being used
- totalRows - an integer representing the total number of rows in the dataset
- errMsg - if an error occurs, this is the message text to be displayed to the user
Debugging
Rico 2.0 includes the ability to route time-stamped debug messages to a message log.
The log may be an html textarea or the browser's javascript console.
LiveGrid is programmed to send a number of messages to the message log that may prove helpful in debugging.
You can also send your own messages by using Rico.writeDebugMsg(). For example:
Rico.writeDebugMsg('My debug message');
Grid Menus
Rico LiveGrids come with a lot of functionality built in. To access that functionality,
Rico includes a default set of menus -- defined in ricoLiveGridMenu.js.
To use the default menu, simply load the 'LiveGridMenu' module and then
assign the grid's menu property to an instance of the Rico.GridMenu class.
Rico.loadModule('LiveGridMenu');
...
var ex1=new Rico.LiveGrid ('ex1', buffer, grid_options);
ex1.menu=new Rico.GridMenu();
By default, the menu will open when a user double-clicks on a grid cell.
To change the event that opens the menu, assign a value to the grid's
menuEvent option. The following code will open the menu on a right-click:
Rico.loadModule('LiveGridMenu');
...
var grid_options = {
menuEvent: 'contextmenu'
}
var ex1=new Rico.LiveGrid ('ex1', buffer, grid_options);
ex1.menu=new Rico.GridMenu();
Rico.GridMenu provides a callback (dataMenuHandler) so that additional menu items can be added.
The grid menu is always built dynamically -- customized to the row and column the user
has clicked on. So the callback function is called every time the menu is invoked and
must add the desired menu items at each invocation.
Rico.loadModule('LiveGridMenu');
...
var ex1=new Rico.LiveGrid ('ex1', buffer, grid_options);
ex1.menu=new Rico.GridMenu();
ex1.menu.options.dataMenuHandler=myCustomMenuItems;
...
function myCustomMenuItems(grid,r,c,onBlankRow) {
if (buffer.getWindowValue(r,c)=='Special Value')
grid.menu.addMenuItem("Special menu item", specialAction);
}
function specialAction() {
...
}
It is also possible to create completely custom menus. For an example,
see ex5.php/asp/aspx.
Notes
Reference
Constructor
var grid = new Rico.LiveGrid (table_id, rico_buffer, grid_options);
- table_id is the DOM id of the table (or div) that will be replaced by a LiveGrid
- rico_buffer is a Rico Buffer object, e.g.
- Rico.Buffer.Base (for non-AJAX tables)
- Rico.Buffer.AjaxXML
- Rico.Buffer.AjaxSQL
- Rico.Buffer.AjaxJSON
- grid_options (see below)
Options
Grid Size
- visibleRows (rows in .net plug-in)
- How many rows of the grid are made visible?
A positive integer specifies that the grid should always contain exactly that many rows.
Negative values have the following meanings:
- -1: size grid to client window (default)
- -2: size grid to whichever is smaller: the client window or the data
- -3: size grid so that the page body does not have a scrollbar
- -4: size grid to the parent node in the DOM
String values have the following meanings:
- 'window': size grid to client window (default)
- 'data': size grid to whichever is smaller: the client window or the data
- 'body': size grid so that the page body does not have a scrollbar
- 'parent': size grid to the parent node in the DOM
- 'XX%': size grid to XX percent of the total window height
- 'XXpx': size grid to XX pixels
- minPageRows
- Minimum # of visible rows. Used only when visibleRows < 0. (default: 2 - after Rico 2b3, 1 - up to Rico 2b3)
- maxPageRows
- Maximum # of visible rows. Used only when visibleRows < 0. (default: 50)
- defaultWidth
- An integer used in setting the initial width of columns.
See the column width option for an explanation.
(default: 100)
- useUnformattedColWidth
- A boolean value used in setting the initial width of columns.
See the column width option for an explanation.
(default: true)
- scrollBarWidth
- For some calculations, LiveGrid needs to know the width of scrollbars on the page. (default: 19)
- minScrollWidth
- Minimum scroll area width in pixels when width of frozen columns exceeds window width. (default: 100)
Grid Data
- offset
- First row of data to be displayed (default: 0)
- prefetchBuffer
- Load the buffer (and therefore the grid) on page load? (default: true)
- sortCol
- Name or index of column for initial sort
- sortDir
- Direction of initial sort
possible values: 'ASC', 'DESC'
- getQueryParms
- If true, check the web page's query string for filter parameters and apply
any filter that is found. Filter parameters must be of the form "f[x]=" where x is the column index.
(default: false)
Header Configuration
- frozenColumns
- number of columns on the left side of the grid that should be
frozen (like Excel).
- headingSort
- A string that defines how headings are displayed to facilitate sorting.
- 'link' -- make headings a link that will sort columns (default)
- 'hover' -- user can click in any part of the heading cell to sort.
Heading changes background color when cursor hovers over cell.
- 'none' -- events on headings are disabled
- hdrIconsFirst
- Put sort and filter icons before or after header text (default: true)
- allowColResize
- Allow columns to be resized by the user? If true, then resizing for individual columns
can be disabled using noResize in columnSpecs[].
- panels
- An array of strings that can serve as secondary headings.
In LiveGrid Forms, they also serve as the headings for the tabbed panels on the input form.
- PanelNamesOnTabHdr
- Set to 'true' for the strings in panels[] to be used as secondary headings.
In LiveGrid Forms, it may be set to 'false' so that panels[] is only used on the input form.
- FilterLocation
- Specifies the heading row where filters should be placed.
-1 causes a new row to be appended to the header and that new row used for filtering.
See also the filterUI option.
- FilterAllToken
- Token in select filters used to indicate "show all values" (default: "___ALL___").
Images
- resizeBackground
- Image to use for column resize handle. (default: 'resize.gif')
- sortAscendImg
- Image to use to indicate that the column is sorted in ascending order. (default: 'sort_asc.gif')
- sortDescendImg
- Image to use to indicate that the column is sorted in descending order. (default: 'sort_desc.gif')
- filterImg
- Image used to indicate an active filter on a column. (default: 'filtercol.gif')
Cookie options
- saveColumnInfo
- Specifies which details to save in the grid's cookie. Only one cookie is used for each grid.
Note that the width setting includes the hide/show status of the column.
(default: {width:true, filter:false, sort:false})
In the .net plug-in, this option is represented by 3 separate properties:
saveColumnWidth, saveColumnFilter, saveColumnSort
- cookiePrefix
- A string that is prepended to the cookie name. (default: 'RicoGrid.')
- cookieDays
- Number of days before the cookie expires.
If you don't specify it, then the cookie is only maintained for the current session. (default: null)
- cookiePath
- Sets the top level directory from which the grid cookie can be read.
If you don't specify it, it becomes the path of the page that sets the cookie. (default: null)
- cookieDomain
- Tells the browser to which domain the cookie should be sent.
If you don't specify it, it becomes the domain of the page that sets the cookie. (default: null)
Highlighting and selection
- highlightElem
- a string that specifies what gets highlighted/selected
- 'cursorRow' -- the grid row under the cursor
- 'cursorCell' -- the grid cell under the cursor
- 'menuRow' -- the grid row where the menu is displayed
- 'menuCell' -- the grid cell where the menu is displayed
- 'selection' -- allow the user to select cells
- 'none' -- never highlight
- highlightSection
- an integer that specifies which section of the table is highlighted
- 1 -- frozen
- 2 -- scrolling
- 3 -- all (default)
- 0 -- none
- highlightMethod
- Method used to highlight cells & rows. Possible values:
- 'outline' -- least CPU-intensive on client-side
- 'class' -- adds CSS class to highlighted cell/row (default)
- 'both' -- highlight using both outline and class
- highlightClass
- When highlighting by class, this is the class name used (default: 'ricoLG_selection')
Export and print
- maxPrint
- The maximum number of rows that the user is allowed
to Print/Export. Set to 0 to disable print/export. (default: 1000)
- exportWindow
- Options string passed to window.open()
when the export window is created. (default: "height=400,width=500,scrollbars=1,menubar=1,resizable=1")
- exportStyleList
- An array of CSS attributes that will be extracted from the first visible row of the grid and used
to format all rows of the exported table.
(default: ['background-color', 'color', 'text-align', 'font-weight', 'font-size', 'font-family'])
Behavior Defaults
- canHideDefault
- Controls whether columns can be hidden/shown (default: true).
Hide/show can be disabled for individual columns using the canHide property in columnSpecs.
- canSortDefault
- Controls whether columns can be sorted (default: true).
Sorting can be disabled for individual columns using the canSort property in columnSpecs.
- canFilterDefault
- Controls whether columns can be filtered (default: true).
Filtering can be disabled for individual columns using the canFilter property in columnSpecs.
Event control
- menuEvent
- A string that specifies when the grid's menu should be invoked
- 'click' -- invoke menu on single-click
- 'dblclick' -- invoke menu on double-click (default)
- 'contextmenu' -- invoke menu on right-click
- 'none' -- no pop-up menu
- windowResize
- A boolean value specifying whether to resize the grid during a window.resize event.
This should be set to false when the grid is embedded in an accordian. (default: true)
Event handles
- Event handlers cannot be passed in options to the constructor, but may be set after the LiveGrid has been constructed.
- sortHandler
- (default: Rico.LiveGridMethods.sortHandler -- bound)
- filterHandler
- (default: Rico.LiveGridMethods.filterHandler -- bound)
- onRefreshComplete
- (default: Rico.LiveGridMethods.bookmarkHandler -- bound)
- rowOverHandler
- (default: Rico.LiveGridMethods.rowMouseOver -- bound as event listener)
- mouseDownHandler
- (default: Rico.LiveGridMethods.selectMouseDown -- bound as event listener)
- mouseOverHandler
- (default: Rico.LiveGridMethods.selectMouseOver -- bound as event listener)
- mouseUpHandler
- (default: Rico.LiveGridMethods.selectMouseUp -- bound as event listener)
- onscroll
- called whenever the grid is scrolled vertically. (default: null)
- onscrollidle
- called 1.2 seconds after the grid is scrolled vertically. (default: null)
- click
- called when a grid cell is clicked. (default: null, unless menuEvent='click')
- dblclick
- called when a grid cell is double-clicked. (default: null, unless menuEvent='dblclick')
- contextmenu
- called when a grid cell is right-clicked. (default: null, unless menuEvent='contextmenu')
Per-column configuration
- Options for each individual column are contained in the columnSpecs option.
columnSpecs is an array with an entry for each column.
Each column entry can either be:
- null (default) -- in which case the column is formatted according to the spec in Rico.TableColumn.DEFAULT.
If most columns in your grid share common formatting, then it may make sense to override
the default column spec for that grid:
Rico.TableColumn.DEFAULT = {ClassName:'aligncenter', width:50};
In this case, any column with no spec will have content aligned to the center and a width of 50 pixels.
- a string -- provides a simple way to specify a column format.
These values are built-in: DOLLAR, EURO, PERCENT, QTY, DEFAULT.
It is also possible to define your own. This example, which defines a temperature format,
is taken from weather.php:
Rico.TableColumn.TEMP = {type:'number', decPlaces:0,
ClassName:'alignright', suffix:'°C', width:50};
var opts = {
frozenColumns : 1,
columnSpecs : [{width:120},{width:70},{width:70},{width:100},
'TEMP','TEMP','TEMP',
{width:150},{width:200},{width:60}]
};
- an object -- containing entries for one or more of the properties listed below.
Here is an example that contains specifications for columns 0, 1, and 3.
Column 2 would get the default spec.
columnSpecs : [{canSort:false, noResize:true, ClassName:'alignright'},
{ClassName:'aligncenter'},
,
{visible:false}]
- Hdg
- An alternate way of specifying the heading text for a column.
Only used by LiveGrid if the grid id refers to a <div> instead of an html table.
- canSort
- Column can be sorted. (default: grid.options.canSortDefault)
- canFilter
- Column can be filtered. (default: grid.options.canFilterDefault)
- canDrag
- Column cells can serve as the source for a drag-n-drop operation. The "DragAndDrop" module must be loaded.
The temporary drag objects have a class of "LiveGridDraggable".
For an example, see drag_and_drop_grid.html. (default: false)
- canHide
- Column can be hidden/unhidden. (default: grid.options.canHideDefault)
- visible
- Controls whether the column is visible at grid startup (default: true).
If grid.options.saveColumnInfo.width is true
and there is a value in the cookie for this column, the cookie value will take precedence.
- width
- An integer specifying the initial width (in pixels) for the column.
Here is the algorithm LiveGrid uses for setting the initial width of each column:
- If options.saveColumnInfo.width is true and column information is present in the grid's cookie
(due to the user previously performing a resize on that grid's column),
then the width in the cookie is used. Otherwise...
- If there is a width spec for the column in options.columnSpecs[], then the width in the spec is used. For an example, see ex3.php/asp/aspx. Otherwise...
- If options.useUnformattedColWidth is true (default) and the grid header is initialized from an html table, then the column's width in the html table is used.
You can usually control the column widths of the initial table by using col tags (e.g. <col style='width:40px;' >).
If the total table width is less than the browser width then this works; however if it is greater, then the browser often ignores <col width>
and tries to squeeze all of the columns into the available window width. Thus, using this method to set the column width is unreliable. Otherwise...
- If options.useUnformattedColWidth is false, then the column's width is set to options.defaultWidth (which defaults to 100).
Therefore, the most reliable way to set column widths in LiveGrid and SimpleGrid is to specify a width for every column in options.columnSpecs[].
If many columns share a common width, then you can shortcut this somewhat by setting options.useUnformattedColWidth=false,
and setting options.defaultWidth to the common width.
- noResize
- Allow column to be resized? (default grid.options.allowColResize )
- ClassName
- By default, LiveGrid assigns a unique CSS class name to each
column, which follows the naming convention: table_id + '_col' + column_index.
For example, the fourth column in the grid 'mygrid' would have the class name
'mygrid_col3'. The value of the ClassName option overrides this default name.
The ClassName option is most commonly used to specify column alignment via the
Rico-provided 'alignright' and 'aligncenter' classes.
So, if you wanted the first 3 columns in your grid to be displayed with white
text on a red background, you could do either of the following:
In CSS:
.mygrid_col0 div.ricoLG_cell,
.mygrid_col1 div.ricoLG_cell,
.mygrid_col2 div.ricoLG_cell {
color: white;
background-color: red;
}
OR
In CSS:
.WhiteOnRed div.ricoLG_cell {
color: white;
background-color: red;
}
In javascript:
columnSpecs : [{ClassName:'WhiteOnRed'},
{ClassName:'WhiteOnRed'},
{ClassName:'WhiteOnRed'},
...
Finally, please note that this ClassName is not applied to the grid headings -
use a align="right" on the <th> tag to accomplish the header alignment.
- type (DataType in .net plug-in)
- A string containing one of these values:
- text - any tags in the column value are removed before being displayed to the user.
- showTags - any tags in the column value are displayed to the user as text.
- number - column value is treated as a number,
and any number formatting options
supplied in the column specification are applied.
- datetime - column value is treated as a date & time,
and any date formatting options
supplied in the column specification are applied.
- UTCasLocalTime - column/database value is treated as a GMT/UTC date & time, and any date formatting options
supplied in the column specification are applied. Before display, the value is converted to the user's local time zone.
- date - column value is treated as a date, and any date formatting options
supplied in the column specification are applied.
- raw (default) - column values are displayed directly to the grid cell.
Any HTML markup gets copied into the cell.
- control
- An object that can be used to provide special formatting for a column.
Several column controls are provided with LiveGrid. The code for them
resides in ricoLiveGridControls.js. Here is a brief description of the
provided controls:
- Rico.TableColumn.checkboxKey(showKey)
- Display unique key column as: <checkbox> <key value>
and keep track of which keys the user selects.
Key values should not contain <, >, or &.
- Rico.TableColumn.checkbox(checkedValue, uncheckedValue, defaultValue, readOnly)
- Display column as checkboxes. Database column should contain only two-values (e.g. yes/no).
The following code is taken from ex7 (column values are 1 and 0):
columnSpecs: [{canHide:false,
control:new Rico.TableColumn.checkbox('1','0'),
ClassName:'aligncenter'},
'specQty'],
- Rico.TableColumn.textbox(boxSize, boxMaxLen, readOnly)
- Display the column value in a text box.
- Rico.TableColumn.HighlightCell(chkcol,chkval,highlightColor,highlightBackground,chkop)
- Highlight a grid cell when a particular value is present in the specified column.
chkop optionally specifies the comparison to be performed: ==, !=, <, <=, >, >=.
If not specified, then == is used.
The following code is taken from ex2highlight and highlights the entire row when column 1
contains "HANAR":
var CustId='HANAR';
var CustIdCol=1;
var highlight=Rico.TableColumn.HighlightCell;
...
columnSpecs: [
{ control:new highlight(CustIdCol,CustId,'red','yellow') },
{ control:new highlight(CustIdCol,CustId,'red','yellow') },
{ control:new highlight(CustIdCol,CustId,'red','yellow') },
{ control:new highlight(CustIdCol,CustId,'red','yellow') },
{ control:new highlight(CustIdCol,CustId,'red','yellow') },
{ type:'date', control:new highlight(CustIdCol,CustId,'red','yellow') },
{ type:'date', control:new highlight(CustIdCol,CustId,'red','yellow') }]
- Rico.TableColumn.bgColor()
- Database value contains a css color name/value
- Rico.TableColumn.link(href,target)
- Database value contains a url to another page.
The href parameter may contain references to grid values by including "{x}" in the string,
where x is a column number. The following code is taken from ex6:
columnSpecs: [,
{control:new Rico.TableColumn.link('ex2.asp?id={0}','_blank'),
width:250},
,'specQty']
- Rico.TableColumn.image()
- Database value contains a url to an image.
The following code is taken from photos.php:
imgctl=new Rico.TableColumn.image();
...
columnSpecs: [
{control:imgctl,width:90},,,
{type:'datetime'},{width:200}]
- Rico.TableColumn.lookup(map, defaultCode, defaultDesc)
- Map a database value to a display value
- Rico.TableColumn.MultiLine()
- Overcomes issues when displaying multi-line content (i.e. content with <br> tags) in IE6 and IE7
It is also possible to write your own column control, which
implements logic specific to your application. Here is an example:
// Display values white on black if
// first column contains the value "reverse"
// Usage: { control:new MyCustomColumn() }
MyCustomColumn = Class.create();
MyCustomColumn.prototype = {
initialize: function() {},
_clear: function(gridCell,windowRow) {
gridCell.style.color='';
gridCell.style.backgroundColor='';
gridCell.innerHTML=' ';
},
_display: function(v,gridCell,windowRow) {
var col0=this.liveGrid.buffer.getWindowValue(windowRow,0);
if (col0=="reverse") {
gridCell.style.color='white';
gridCell.style.backgroundColor='black';
} else {
gridCell.style.color='';
gridCell.style.backgroundColor='';
}
gridCell.innerHTML=this._format(v);
}
}
- filterUI
- If a FilterLocation option is specified for the grid, then filterUI will control
how each column is filtered. If filterUI is:
- filterCol
- Specifies that the filter should be applied to a different column. For example, ex3livegrid.asp/aspx/php
uses this feature to filter the order and ship date columns by year. The full date is shown in the column
in which the filter appears; however, there is another hidden, calculated column containing "year(orderdate)"
to which the filter is applied.
- Number formatting:
- multiplier
- The value is multiplied by this number before it is displayed. (default: 1)
- decPlaces
- Number of places to the right of the decimal point. (default: 0)
- decPoint
- Decimal point symbol. (default: '.' but overridden in the translation files)
- thouSep
- Symbol for thousands separator. (default: ',' but overridden in the translation files)
- negSign
- Specifies how negative numbers should be displayed. Possible values:
- L=leading minus (default)
- T=trailing minus
- P=parentheses
- prefix
- A string added to the beginning of the number. Typically a currency symbol.
- suffix
- A string added to the end of a number. For example, a "%" symbol.
- Date formatting:
- dateFmt
- A string specifying how the date or datetime should be displayed. Default is "translateDate", which means
that the dateFmt and timeFmt strings in the RicoTranslate object are used
(this defaults to "mm/dd/yyyy" for dates and "mm/dd/yyyy hh:nn:ss a/pm" for datetimes,
but is overridden by the various language translation files).
If dateFmt="localeDate", then the value is formatted using javascript's built-in toLocaleDateString() function.
If dateFmt="localeDateTime", then the value is formatted using javascript's built-in toLocaleString() function.
The dateFmt string may contain the following special character sequences:
- yyyy - 4 digit year
- yy - 2 digit year
- mmmm - month name
- mmm - 3 character month name abbreviation. In Asian languages this often doesn't make sense - in these cases it returns the full month name (same as mmmm).
- mm - 2 digit month number (zero padded)
- m - 1 or 2 digit month number
- dddd - day-of-the-week
- ddd - 3 character day-of-the-week abbreviation
- dd - 2 digit day number (zero padded)
- d - 1 or 2 digit day number
- hh - 2 digit hour, 12-hour clock (zero padded)
- h - 1 or 2 digit hour, 12-hour clock
- HH - 2 digit hour, 24-hour clock (zero padded)
- H - 1 or 2 digit hour, 24-hour clock
- nn - 2 digit minutes (zero padded)
- ss - 2 digit seconds (zero padded)
- a/p - a or p (for am or pm)
// display first column as "month year"
columnSpecs : [{type:date, dateFmt:'mmm yyyy'}]
- prefix
- A string added to the beginning of the date.
- suffix
- A string added to the end of a date. For example, you could use this to include a time zone:
// indicate that times are GMT/UTC
columnSpecs : [{type:datetime, suffix:' UTC'}]