LabKey Server provides a rich API for building client applications on top of LabKey Server -- for example, applications that retrieve and interact with data from the database. To get started building a client application, LabKey Server can generate a client script that retrieves a grid of data from the database. Adapt and extend the scripts capabilities to meet your needs. You can generate a script snippet for any data grid. The following script languages are supported:
To generate a script for a given dataset:
For example, the Physical Exam dataset in the LabKey Demo Study can be retrieved using this snippet of JavaScript:
<script type="text/javascript">
LABKEY.Query.selectRows({
requiredVersion: 9.1,
schemaName: 'study',
queryName: 'Physical Exam',
columns: 'ParticipantId,date,height_cm,Weight_kg,Temp_C,SystolicBloodPressure,DiastolicBloodPressure,Pulse,
Respirations,Signature,Pregnancy,Language,ARV,ARVtype',
filterArray: null,
sort: null,
success: onSuccess,
error: onError
});
function onSuccess(results)
{
var data = "";
var length = Math.min(10, results.rows.length);
// Display first 10 rows in a popup dialog
for (var idxRow = 0; idxRow < length; idxRow++)
{
var row = results.rows[idxRow];
for (var col in row)
{
data = data + row[col].value + " ";
}
data = data + "n";
}
alert(data);
}
function onError(errorInfo)
{
alert(errorInfo.exception);
}
</script>
Filters. Filters that have been applied to the grid view are included in the script. Note that some module actions apply special filters to the data (e.g., an assay may filter based on a "run" parameter in the URL); these filters are not included in the exported script. Always test the generated script to verify it's retrieving the data you expect, and modify the filter parameters as appropriate.
Column List. The script explicitly includes a column list so the column names are obvious and easily usable in the code.
Foreign Tables. The name for a lookup column will be the name of the column in the base table, which will return the raw foreign key value. If you want a column from the foreign table, you need to include that explicitly in your view before generating the script, or add "/<ft-column-name>" to the field key.
JavaScript Examples.
previousnext |
expand allcollapse all |