# Table Output for Query Web Service

> Source: https://manual.pvxplus.com/table-output-for-query-web-service

With PxPlus 2016, you have the capability to return the data output for an existing query in a table format on a Web page. A new output type of TABLE has been added to the Query Service (qry.pxp) that returns an inner HTML for a table with \<th> for the header and \<td> for the data columns. For information on Web Services, see **[PxPlus Web Services](https://manual.pvxplus.com/pxplus-web-services)**.

Additional options are available for the TABLE output type:

|  |  |  |
| --- | --- | --- |
|  | *LIMIT=nnn* | Limits the number of rows |
|  | *HEADER=no* | Suppresses the column headers |

A simple JavaScript utility **(\*web/services/pxplus.js**) is provided that contains a routine (**PlusQryTable**) for populating the table.

***Calling Sequence:***

**PlusQryTable** (*QryName*, *TableId*, *InputId*, *Options*, *ServerURL*)

***Where:***

|  |  |  |
| --- | --- | --- |
|  | *QryName* | ***(Required)*** Name of the query used to populate the table |
|  | *TableId* | ***(Required)*** ID of the HTML table whose contents will be loaded from the Query data (including the header) |
|  | *InputID* | ***(Optional)*** ID of the HTML INPUT field whose value will be passed as a Global variable to the query  <br>  <br>***Example:***  <br>  <br>'INVOICE' would set %INVOICE$ to the value in the HTML input whose ID was INVOICE. |
|  | *Options* | ***(Optional)*** A string with additional options needed to run the query such as LIB= |
|  | *ServerURL* | ***(Optional)*** URL to the server if not the same as the current server |

Note:  
Trailing optional fields may be omitted from the CALL. Interim optional fields should be passed as null or 0.

To add the JavaScript function, the HTML page must include a script load of the **/services/pxplus.js** source file using something similar to the following:

\<script src="/services/pxplus.js">\</script>

***Example:***

INV_QRY is a query defined in the APP.EN directory. This query displays invoice information, and one of the columns (ClientId$) contains Client Code numbers. As a filter, the **Selection Logic** for the query (see **[Query Selection Criteria](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-selection-criteria)**) checks if a global variable (%ClientId$) is populated, and if so, the record is only included if ClientId$=%ClientId$.

![INV_QRY Query Definition window showing invoice fields, including ClientId$.](https://manual.pvxplus.com/migration-assets/59ee13c98978d08559fa59e9211d9096631d95724112312666dd401c7315e789.jpg)

***Sample file TEST_Q.HTML:***

```
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>Qry Table load Sample HTML</title>
</head>

<body>

<script src="/services/pxplus.js"></script>

<div onclick="PlusQryTable('INV_QRY', 'mytbl', null, 'lib=app.en');" style='text-decoration: underscore;'>Click to load all records</div>

Client ID: <input type='text' width=10 id="clientid" onchange="PlusQryTable('INV_QRY', 'mytbl', 'clientid', 'lib=app.en');" />

<br /><br />

<table width=50% border="1" cellpadding="0" cellspacing="0"
id="mytbl">
     <tr>
          <td width="100%">&nbsp;</td>
     </tr>
</table>
</body>
</html>
```

This sample HTML code demonstrates the use of the **PlusQryTable** routine in two different ways:

|  |  |
| --- | --- |
| ***Method 1:*** | ![PlusQryTable call attached to the Click to load all records text.](https://manual.pvxplus.com/migration-assets/a347bc165372ed308a83f39eec7019210bf8713fb0edc01308ed6581ffddc295.png)  <br>  <br>Clicking on the text *Click to load all records* will populate the table *mytbl* with the entire contents of the file, as illustrated below.<br>![Query table populated with all invoice records.](https://manual.pvxplus.com/migration-assets/b9b668dd5552bd57f64ca5a4786d312f65d17b50da62985704194a42129eff06.jpg) |
| ***Method 2:*** | Entering a *Client ID* number in the text field will populate the %ClientId$ variable, filtering the data by Client ID, as illustrated below.<br>![Query table filtered by the entered Client ID.](https://manual.pvxplus.com/migration-assets/c3da0a1ecbc76305427bca5195356f93f4798936b7d9e3f6984b529e5921dc1f.jpg) |

If you want to suppress the table header or limit the number of records returned, add the optional parameters to the options string passed to the **PlusQryTable** routine as follows:

```
PlusQryTable('INV_QRY', 'mytbl', null, 'lib=app.en&header=no&limit=3')
```
