XGrid |
XGrid is an AJAX toolkit library (API) that can be used to display tabular data. It can be used to construct multi-functional, high-performance grids. XML data is the basis of the content in an XGrid.
XGrid enables the following functionality in a table:
- Support for multiple field types in an Xgrid, such that the fields in a column can be of the type input, output, checkbox, password, textarea, or image (as a thumbnail or composite icon).
- Support for the zoom feature for column cells of the type input, output, textarea, and image. The lookup button appears when focus is set on the cell associated with the zoom feature.
- Support for the calendar control feature for column fields of the type input, for which the data type specified is date.
- Availability of context menu on the column header that offers additional options.
- Availability of column chooser for hiding and displaying columns at runtime.
- Resizing of columns by dragging the edge of the header cells.
- Repositioning of columns by dragging the header cells.
- Freezing of one or more columns such that the columns remain fixed when the horizontal scroll bar is used. Frozen columns are always positioned in front of other non-frozen columns.
- Freezing of one or more rows such that the rows remain fixed when the vertical scroll bar is used. Frozen rows are always positioned on top of other non-frozen rows.
- Sorting of rows according to the data type of the columns in the table.
- Navigation through cells in the table using keyboard keys such as the arrow keys and the Home, End, and Tab keys.
- Selection of multiple rows using the Checkrow column.
The XGrid library can handle large amounts of data, and decreasing startup time and providing a smoother scrolling behavior. To achieve and maintain its superior performance, observe the following guidelines:
- Avoid a combination of large number of rows (more than 250) and columns for smoother scrolling. Also, avoid frozen columns if possible.
- Use images only where necessary to decrease startup time. Also, if you want to use images larger than the standard row height and do not want to display them as thumbnails, set the fixedRowHeight property of the XGrid to False.
- Avoid adding complex scripts for the onbeforedatabind event (fired for each cell when rendered) or the onbeforerowdatabind event (fired for each row when rendered), as it reduces the startup time and affects scrolling behavior.
- Avoid selecting a large number of rows (more than 10,000) using the onrowcheck event and sorting a column containing a large number of rows (more than 5000) as it also affects the performance.
Syntax
HTML |
< div cordysType="wcp.library.ui.XGrid" |
Scripting |
application.addType(xgridId, "wcp.library.ui.XGrid") |
To dynamically add and initialize this component, you can use the initializeHTMLElements or addType methods of the Application object.
Properties, Methods, and Events in XGrid
The various properties, methods, and events that are defined for the XGrid component are as follows.
The following table describes the attributes that are available at the XGrid level.
Table 1. Attributes used for XGrid |
|
|
---|---|---|
Attribute |
Property |
Description |
fixedRowHeight |
n/a |
Boolean with default value as true. If not specified, it is automatically set by the XGrid. |
freezableColumns |
n/a |
Boolean with default value as true. |
freezableRows |
n/a |
Boolean with default value as true. |
hideableColumns |
n/a |
Boolean with default value as true. |
id |
id |
String; required, read only. |
movableColumns |
n/a |
Boolean with default value as true. |
resizableColumns |
n/a |
Boolean with default value as true. |
shadeClasses |
shadeClasses |
String that defines the classes to be used to shading the Xgrid. The classes must be separated by spaces. For example, shadeClasses='light lightmedium'. |
sortable |
n/a |
Boolean with default value as true. |
useCheckboxes |
n/a |
Boolean with default value as true. |
useRowCache |
n/a |
Boolean with default value as true. |
Required, read only. Sets the XPath from the rowData to the businessObject. |
||
Required, read only. Sets the XPath from the dataNode to the row data elements. The rowData, the top node of a row, is the repeating level in the XML data. |
The following table describes the attributes that are applicable to columns in an XGrid.
Table 2. Attributes used for columns in XGrid |
|
---|---|
Attribute |
Description |
class |
String. Optional. |
dataType |
String. Optional attribute with default value as string. |
dropdownId |
String. |
falseValue |
String. The default value is false. |
fieldType |
String. Optional attribute with default value as input. |
id |
String. Optional. |
<label> |
String. Optional. |
String. Required. |
|
thumbnail |
Boolean. Optional attribute with default value as false. |
iconSize |
Optional. String that denotes the size of icons in a Column. Possible values are:
|
title |
String. Optional. |
trueValue |
String. The default value is true. |
width |
Integer. Optional. |
zoomField |
String. Applicable to cells that have a zoom option. The zoomField is available as a parameter in the onzoom event. The zoom field usually has the id of the field on the zoom page that has the data to be returned. |
String. Applicable to cells that have a zoom option. The zoomUrl is available as a parameter in the onzoom event. The zoom URL usually has the URL of the page you zoom to. |
|
Table 3. Methods used with XGrid |
|
Method |
Description |
addColumn(id, ref, label, fieldType, dataType, misc1, misc2, bApplyPreferenceState) |
Dynamically creates an extra column. |
Binds the passed data node, resulting in the rendering of this data in the XGrid. |
|
blur() |
Removes the focus from the selected cell and row. |
Checks or clears all rows. To be able to use this method, you must set the useCheckboxes property to true. For each row an onrowcheck event is fired. |
|
clearData() |
Clears all data from an XGrid. |
Removes all checked rows and deletes the corresponding rowData. This method should be used only for non-transactional data. |
|
disable() |
Disables the entire XGrid. |
enable() |
Enables the entire XGrid. |
Freezes or unfreezes the selected rows depending on bSelect. |
|
getCell(column, iRow) |
Returns the cell object for the specified column and row.
|
Returns an array containing row objects of all checked rows. The remove(), freeze(), and unfreeze() methods can be used to handle all objects in the array. |
|
getColumn(column) |
Returns the column object of the specified column.
|
getData() |
Returns the XML data associated with the XGrid. This data is linked to the XGrid using the bindData() method. |
Returns a rowObject of the first row of the XGrid. |
|
getFreezableColumns() |
Returns the freezableColumns property, which determines whether columns can be frozen or not. |
getFreezableRows() |
Returns the freezableRows property, which determines whether rows can be frozen or not. |
getHideableColumns() |
Returns the hideableColumns property, which determines whether columns can be hidden or not. |
Returns the rowObject of the last row of the XGrid. |
|
getMovableColumns() |
Returns the movableColumns property, which determines whether columns can be moved or swapped, or not. |
Returns the next row object with respect to the passed row object. |
|
getNumberOf Rows() |
Returns an integer, which gives the total number of rows in the XGrid. |
getNumberOfVisibleRows() |
Returns an integer, which gives the number of rows visible to the user (without scrolling). |
Returns the previous row object with respect to the passed row object. |
|
getResizableColumns() |
Returns the resizableColumns property, which determines whether columns can be resized or not. |
Returns the row object of the passed row. iRow can be the rowData, the HTML of the row or the row index. The index of the first row is 1. |
|
Returns a rowObject from the highlighted row selected by the user. |
|
getSortable() |
Returns the sortable property, which determines whether rows can be sorted or not. |
getSortedColumn() |
Returns an object of the last sorted column. The object has two properties:
|
getUseCheckboxes() |
Returns boolean that refers to the useCheckboxes property. |
getUseRowCache() |
Boolean that indicates if the rendered row data is cached. |
hide() |
Hides the entire XGrid. |
hideFooter() |
Hides the footer area of the XGrid. |
hideHeader() |
Hides the header area of the XGrid. |
Prepares a node for the XGrid. The node itself is not automatically added to the XML of the XGrid. The rowData must have the same parent as all the other rowData nodes. |
|
refresh() |
Refreshes the rows of the XGrid. The rows are recreated based on the available data. The scroll position is retained. |
setFreezableColumns(bSelect) |
Sets the freezableColumns property, which determines whether columns can be frozen or not. |
setFreezableRows(bSelect) |
Sets the freezeableRows property, which determines whether rows can be frozen or not. |
setHideableColumns(bSelect) |
Sets the hideableColumns property, which determines whether columns can be hidden or not. |
setMovableColumns(bSelect) |
Sets the movableColumns property, which determines whether columns can be moved or swapped, or not. |
setResizableColumns(bSelect) |
Sets the resizableColumns property, which determines whether columns can be resized or not. |
setShadeClasses(sShadeClasses) |
Sets the shadeClasses.
|
setSortable(bSelect) |
Sets the sortable property, which determines whether rows can be sorted or not. |
setUseCheckboxes(bSelect) |
Sets the useCheckboxes property. Adds or removes the check boxes column. |
setUseRowCache(bSelect) |
Boolean that indicates if the rendered row data must be cached. |
show() |
Shows a (hidden) XGrid. |
showFooter() |
Displays (the previously hidden) footer area of the XGrid. |
showHeader() |
Displays (the previously hidden) header of the XGrid. |
The following table describes the events that are applicable to the XGrid.
Table 4. Events used with XGrid |
|
---|---|
Event |
Description |
Executed after rows have been sorted. |
|
Executed before rows have been sorted. |
|
Executed before a row is rendered. |
|
Executed when you double-click a row. |
|
Executed when you right-click a cell. |
|
Executed when a row is (un)checked. A row can be checked by selecting its corresponding check row checkbox, selecting the check all rows checkbox in the header, or using the checkAllRows() method. |
|
onrowhover |
Executed when you hover on (mouse over) a row. The event properties of this event are similar to those of the ondblclick event. |
Executed when a row is selected. |
|
onrowunhover |
Executed when you stop the mouse over action on a row. The event properties of this event are similar to those of the ondblclick event. |
The following table describes the events that are applicable to cells in an XGrid.
Table 5. Events used for cells in XGrid |
|
---|---|
Event |
Description |
Executed just before the value of a cell is written. |
|
Executed when a cell loses focus. |
|
Executed when you click the calendar icon in a column of the date dataType. Here a calendar control can be displayed. The calendar icon is displayed only when the oncalendarselect event has been defined. |
|
Executed when the content of a cell is changed. The value of the dataNode corresponding to the edited cell, is also updated by the XGrid. If the dataNode does not exist, it is created and its value updated after the onchange event has been executed. This allows you to create a dataNode. |
|
Executed when a cell receives focus. |
|
Executed when you click the zoom icon in a cell. The zoom icon is displayed only when a zoom event is defined. |
Remarks
You can observe from the syntax that columns are defined using the <div> nodes at design time. At runtime, these are replaced by the actual XGrid HTML structure and therefore references made to these nodes are lost. The XGrid is a <div> table and does not use the standard <table> tag of HTML, due to which the HTML table functions cannot be used.
XGrids provide high performance and low memory usage, and can handle large amounts of data. To enable working with large amounts of data, the amount of HTML rendered is minimal and is not made available for each row. Therefore, instead of editing the HTML structure, you must use the available API to perform any required data manipulations.
XML data is the basis for creating rows. The XML nodes that represent rows in an XGrid are associated with an attribute, which is used for identification and for facilitating quick search. The following is an example of a typical XML structure:
<data>
<GetEmployeesResponse
xmlns="http://schemas.cordys.com/1.0/demo/northwind">
<tuple _xgrid_rowDataId="0">
<old>
<Employees>
<EmployeeID>1</EmployeeID>
<FirstName>Nancy</FirstName>
<LastName>Davolio</LastName>
</Employees>
</old>
</tuple>
<tuple _xgrid_rowDataId="1">
<old>
<Employees>
<EmployeeID>2</EmployeeID>
<FirstName>Andrew</FirstName>
<LastName>Fuller</LastName>
</Employees>
</old>
</tuple>
</GetEmployeesResponse>
</data>
In this example, the <tuple> represents the basis for a row (rowData node), the _xgrid_rowDataId is added by XGrid. The order of the rowData elements (<tuple>) is altered by XGrid when sorting and freezing rows.
The width of the columns and the width of the XGrid are not related. Resizing columns has no influence on the size of the XGrid, and resizing the XGrid has no influence on the width of the columns. This allows you maximum control over the table dimensions.
Example
This sample demonstrates the implementation and use of the XGrid component.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html onapplicationready="getData()">
<head>
<title>xpath demo</title>
<script src="/cordys/wcp/application.js"></script>
<script>
function getData()
{
//collects data from busdataIsland and bind to xgrid
bdiEmployees.reset();
employeesGrid.bindData( bdiEmployees.data );
}
</script>
<script type="cordys/xml" id="requestGetEmployees">
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<GetEmployeesObjects xmlns="http://schemas.cordys.com/DemoWebServices">
<fromEmployeeID>1</fromEmployeeID>
<toEmployeeID>10</toEmployeeID>
</GetEmployeesObjects>
</SOAP:Body>
</SOAP:Envelope>
</script>
</head>
<body scroll="no" leftmargin="0" topmargin="0">
<div cordysType="wcp.library.data.BusDataIsland" async="false" id="bdiEmployees" automatic="false" request="requestGetEmployees.XMLDocument"></div>
<div style="width:100%;height:100%;overflow:hidden">
<div cordysType="wcp.library.ui.XGrid" id="employeesGrid"
xpathRowData = ".//*[local-name()='data']/*[local-name()='GetEmployeesObjectsResponse']/*[local-name()='tuple']"
xpathBusinessObject = ".//*[local-name()='Employees']"
style="width:95%;height:70%">
<div id="EmployeeID" ref=".//*[local-name()='EmployeeID']" dataType="integer">EmployeeID</div>
<div id="FirstName" ref=".//*[local-name()='FirstName']">FirstName</div>
<div id="LastName" ref=".//*[local-name()='LastName']">LastName</div>
</div>
</div>
</body>
</html>