Grid widget on Manual Windows
Contents |
Introduction
Glossary
The AJAX grid widget overview
Note: Further details will be explained later. This is an overview.
- The grid was implemented as a dojo widget. http://dojotoolkit.org/
- To use the grid widget you need to made changes on the html, xml, java, xsql files. The changes will be explained in parts.
- The grid makes two AJAX requests in the first load.
- Request for structure
- In this request, the servlet must respond with a valid xml structure.
- Request for data
- The reponse is the data formatted as xml used as rows in the grid.
- Request for structure
- When you need filter the data, you need the create an javascript array with each one of the filter parameters, pass to the grid, and make a request for data update.
- Each row needs a unique indentifier, be aware of that. E.g. In the Business Partner selector is a concatenation:C_BPartner_ID#C_BPartner_Contact_ID#C_BPartner_Location_ID
- You need to make a handler (e.g. depurarSelector) for the doubleclick event. This should get all the necessary parameters an pass it to the window.
- The selector must return an array of parameters; those are Out parameters in the selector definition. (Application Dictionary || Reference || Reference >> Selector Reference >> Selector Reference Columns)
HTML
The html has three DIV containters (client_top, client_middle, client_bottom). This has also new JavaScript functions to handle the grid actions (filter, select).
The grid DIV tag
<DIV id="grid" dojotype="openbravo:DataGrid" structureurl="../info/BusinessPartner.html?Command=STRUCTURE" dataurl="../info/BusinessPartner.html?Command=DATA" updatesurl="../info/BusinessPartner_F1.html?Command=DATA" calculatenumrows="true" editable="false" sortable="true" deleteable="true" oninvalidvalue="alert" onscroll="updateHeader" ongridload="onGridLoadDo" buffersize="3.0" showlinenumbers="true" offset="" sortcols="1" sortdirs="ASC" defaultrow="0" maxwidth="99%" percentagewidthrelativetoid="client_middle" multiplerowselection="false" preventcache="true" usecache="true" cachecontent="false">
</DIV>
<SCRIPT>djConfig.searchIds.push("grid");</SCRIPT>
JavaScript
Several javascript functions were added to the page.
The list of files to include:
<SCRIPT language="JavaScript" src="../web/js/openbravo/widget/DataGrid.js" type="text/javascript"></SCRIPT> <SCRIPT language="JavaScript" src="../web/js/windowKeyboard.js" type="text/javascript"></SCRIPT> <SCRIPT language="JavaScript" src="../web/js/searchs.js" type="text/javascript"></SCRIPT>
XML
You need to add the the xml parameters for the grid:
<PARAMETER id="grid" name="grid" attribute="numrows" />
<PARAMETER id="grid" name="grid_Offset" attribute="offset" />
<PARAMETER id="grid" name="grid_SortCols" attribute="sortcols" />
<PARAMETER id="grid" name="grid_SortDirs" attribute="sortdirs" />
<PARAMETER id="grid" name="grid_Default" attribute="defaultrow" />
Java
- All the methods the generates frames were replaced
void printPage() {
...
xmlDocument.setParameter("grid", "20");
xmlDocument.setParameter("grid_Offset", "");
xmlDocument.setParameter("grid_SortCols", "1");
xmlDocument.setParameter("grid_SortDirs", "ASC");
xmlDocument.setParameter("grid_Default", "0");
...
}
- New methods should be added
void printGridStructure(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
}
void printGridData(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strName, String strContact, String strZIP, String strProvincia, String strBpartners, String strCity, String strOrderBy, String strOffset, String strPageSize ) throws IOException, ServletException {
}
private SQLReturnObject[] getHeaders(VariablesSecureApp vars) {
}
/* The colum name are retreived from database. You need to add a new message for each column of the selector. In this case a suffix of BPS_ was used (stands for Business Partner Selector) If the key was not found, the column name is used */
private SQLReturnObject[] getHeaders(VariablesSecureApp vars) {
...
for(int i=0; i < colNames.length; i++) {
...
String name = Utility.messageBD(this, "BPS_" + colNames[i].toUpperCase(), vars.getLanguage());
dataAux.setData("name", (name.startsWith("BPS_")?colNames[i]:name));
...
}
...
}
/* Handling the Oracle/PostgreSQL limit*/
E.g.
// Filtering result
if(this.myPool.getRDBMS().equalsIgnoreCase("ORACLE")) {
String oraLimit = strOffset + " AND " + String.valueOf(Integer.valueOf(strOffset).intValue() + Integer.valueOf(strPageSize));
data = BusinessPartnerData.select(this, "ROWNUM", Utility.getContext(this, vars, "#User_Client", "BusinessPartner"), Utility.getContext(this, vars, "#User_Org", "BusinessPartner"), strKey, strName, strContact, strZIP, strProvincia, (strBpartners.equals("costumer")?"clients":""), (strBpartners.equals("vendor")?"vendors":""), strCity, strOrderBy, oraLimit, "");
}
else {
String pgLimit = strPageSize + " OFFSET " + strOffset;
data = BusinessPartnerData.select(this, "1", Utility.getContext(this, vars, "#User_Client", "BusinessPartner"), Utility.getContext(this, vars, "#User_Org", "BusinessPartner"), strKey, strName, strContact, strZIP, strProvincia, (strBpartners.equals("costumer")?"clients":""), (strBpartners.equals("vendor")?"vendors":""), strCity, strOrderBy, "", pgLimit);
}
Reponses examples
Structure
<xml-structure>
<status>
<type>Hidden</type>
<title></title>
<description></description>
</status>
<datagrid readonly="true" fixed="false">
<columns>
<column name="value" identifier="false" visible="true" title="Key" type="string" width="98px"></column>
<column name="name" identifier="false" visible="true" title="Name" type="string" width="172px"></column>
<column name="so_creditavailable" identifier="false" visible="true" title="Disp. Credit" type="string" width="50px"></column>
<column name="so_creditused" identifier="false" visible="true" title="Credit used" type="string" width="83px"></column>
<column name="contact" identifier="false" visible="true" title="Contact" type="string" width="104px"></column>
<column name="phone" identifier="false" visible="true" title="Phone" type="string" width="63px"></column>
<column name="pc" identifier="false" visible="true" title="Zip" type="string" width="43px"></column>
<column name="city" identifier="false" visible="true" title="City" type="string" width="100px"></column>
<column name="income" identifier="false" visible="true" title="Income" type="string" width="63px"></column>
<column name="c_bpartner_id" identifier="false" visible="false" title="c_bpartner_id" type="string" width="0px"></column>
<column name="c_bpartner_contact_id" identifier="false" visible="false" title="c_bpartner_contact_id" type="string" width="0px"></column>
<column name="c_bpartner_location_id" identifier="false" visible="false" title="c_bpartner_location_id" type="string" width="0px"></column>
<column name="rowkey" identifier="true" visible="false" title="rowkey" type="string" width="0px"></column>
</columns>
</datagrid>
</xml-structure>
Data
<xml-data>
<status>
<type><![CDATA[Hidden]]></type>
<title><![CDATA[]]></title>
<description><![CDATA[]]></description>
</status>
<rows numRows="1">
<tr>
<td><![CDATA[10000238]]></td>
<td><![CDATA[The South Bank]]></td>
<td><![CDATA[-1823.86]]></td>
<td><![CDATA[1823.86]]></td>
<td><![CDATA[]]></td>
<td><![CDATA[]]></td>
<td><![CDATA[ ]]></td>
<td><![CDATA[Capital of Maine]]></td>
<td><![CDATA[ ]]></td>
<td><![CDATA[1004342]]></td>
<td><![CDATA[]]></td>
<td><![CDATA[1004091]]></td>
<td><![CDATA[1004342##1004091]]></td>
</tr>
</rows>
</xml-data>
XSQL
The xsql was modified to permit the limit of a resultset. To the previous sql clause you need to add:
<SqlMethod name="select" type="preparedStatement" return="multiple">
<SqlMethodComment></SqlMethodComment>
<Sql> <![CDATA[
SELECT * FROM ( SELECT '0' AS RN1, A.* FROM (
{PREVIOUS SELECT}
) A ) B
WHERE 1=1
]]></Sql>
<Parameter name="rownum" type="replace" optional="true" after="FROM ( SELECT " text="'0'" />
{PREVIOUS PARAMETERS}
<Parameter name="oraLimit" type="argument" optional="true" after="WHERE 1=1" text="bp.value"><![CDATA[AND RN1 BETWEEN ]]></Parameter>
<Parameter name="pgLimit" type="argument" optional="true" after="WHERE 1=1" text="bp.value"><![CDATA[LIMIT ]]></Parameter>=== Application Dictonary ===
- Add the new messages to grid column name translation.
Category: Development


