Difference between revisions of "HTML Presentation Object: Get cell value from dataset"
Jump to navigation
Jump to search
(Created page with "<pre> <div id="container<#uniqueId>"></div> <style> #container<#uniqueId> { margin: 10px 0px 0px 15px; font-size: 15px; } </style> <script> var datasetIdentifier<#unique...") |
m (Ollvihe moved page Get cell value from dataset using HTML Presentation Object to HTML Presentation Object: Get cell value from dataset without leaving a redirect) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | The following example shows how to get a single cell value from a dataset and present it in an HTML presentation object. The functionality is similar as in the expression language [[Expression Tag in QPR UI#Cell function|Cell function]]. | ||
+ | |||
+ | Configurable JavaScript variables are (corresponding to the [[Expression Tag in QPR UI#Cell function|Cell function]] parameters): | ||
+ | * datasetIdentifier<#uniqueId> | ||
+ | * columnNameOrIndex<#uniqueId> | ||
+ | * rowNumber<#uniqueId> | ||
+ | * defaultValue<#uniqueId> | ||
+ | |||
<pre> | <pre> | ||
<div id="container<#uniqueId>"></div> | <div id="container<#uniqueId>"></div> | ||
Line 11: | Line 19: | ||
<script> | <script> | ||
var datasetIdentifier<#uniqueId> = "myDataset1"; | var datasetIdentifier<#uniqueId> = "myDataset1"; | ||
− | var columnNameOrIndex<#uniqueId> = | + | var columnNameOrIndex<#uniqueId> = 1; //can be defined as column name (string) |
− | var rowNumber<#uniqueId> = | + | var rowNumber<#uniqueId> = 1; |
var defaultValue<#uniqueId> = "default value"; | var defaultValue<#uniqueId> = "default value"; | ||
var poData<#uniqueId>; | var poData<#uniqueId>; | ||
Line 22: | Line 30: | ||
} | } | ||
− | function datasetAvailable<#uniqueId>(datasetData) { | + | function datasetAvailable<#uniqueId>(datasetData) { |
if (datasetData == null || datasetData.sheets == null || datasetData.sheets.length == 0 || datasetData.sheets[0] == null || datasetData.sheets[0].values == null || datasetData.sheets[0].values.length == 0) return; | if (datasetData == null || datasetData.sheets == null || datasetData.sheets.length == 0 || datasetData.sheets[0] == null || datasetData.sheets[0].values == null || datasetData.sheets[0].values.length == 0) return; | ||
Line 43: | Line 51: | ||
if (columnIndex == null) { | if (columnIndex == null) { | ||
textboxValue = "Column name \"" + columnNameOrIndex<#uniqueId> + "\" wasn't found."; | textboxValue = "Column name \"" + columnNameOrIndex<#uniqueId> + "\" wasn't found."; | ||
+ | } else if (columnIndex < 1) { | ||
+ | textboxValue = "Column index cannot be lower than 1 (" + columnIndex + ")"; | ||
+ | } else if (rowNumber<#uniqueId> < 1) { | ||
+ | textboxValue = "Row number cannot be lower than 1 (" + rowNumber<#uniqueId> + ")"; | ||
} else if (datasetData.sheets[0].values.length < columnIndex) { | } else if (datasetData.sheets[0].values.length < columnIndex) { | ||
if (defaultValue<#uniqueId> == null) { | if (defaultValue<#uniqueId> == null) { | ||
Line 55: | Line 67: | ||
textboxValue = defaultValue<#uniqueId>; | textboxValue = defaultValue<#uniqueId>; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
} else { | } else { | ||
textboxValue = datasetData.sheets[0].values[columnIndex - 1][rowNumber<#uniqueId>].value; | textboxValue = datasetData.sheets[0].values[columnIndex - 1][rowNumber<#uniqueId>].value; | ||
Line 68: | Line 76: | ||
</script> | </script> | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category: QPR UI]] |
Latest revision as of 16:46, 6 February 2018
The following example shows how to get a single cell value from a dataset and present it in an HTML presentation object. The functionality is similar as in the expression language Cell function.
Configurable JavaScript variables are (corresponding to the Cell function parameters):
- datasetIdentifier<#uniqueId>
- columnNameOrIndex<#uniqueId>
- rowNumber<#uniqueId>
- defaultValue<#uniqueId>
<div id="container<#uniqueId>"></div> <style> #container<#uniqueId> { margin: 10px 0px 0px 15px; font-size: 15px; } </style> <script> var datasetIdentifier<#uniqueId> = "myDataset1"; var columnNameOrIndex<#uniqueId> = 1; //can be defined as column name (string) var rowNumber<#uniqueId> = 1; var defaultValue<#uniqueId> = "default value"; var poData<#uniqueId>; function <#datasetChangeFunction>(datasetIdentifier, datasetChangeCallbackFunction) { if (datasetIdentifier == datasetIdentifier<#uniqueId>) { datasetChangeCallbackFunction(datasetAvailable<#uniqueId>); } } function datasetAvailable<#uniqueId>(datasetData) { if (datasetData == null || datasetData.sheets == null || datasetData.sheets.length == 0 || datasetData.sheets[0] == null || datasetData.sheets[0].values == null || datasetData.sheets[0].values.length == 0) return; if (columnNameOrIndex<#uniqueId> == null) columnNameOrIndex<#uniqueId> = 1; if (rowNumber<#uniqueId> == null) rowNumber<#uniqueId> = 1; var columnIndex = null; if (typeof columnNameOrIndex<#uniqueId> == "string") { for (var index = 0; index < datasetData.sheets[0].values.length; index++) { if (datasetData.sheets[0].values[index][0].value == columnNameOrIndex<#uniqueId>) { columnIndex = index + 1; break; } } } else { columnIndex = columnNameOrIndex<#uniqueId>; } var textboxValue = null; if (columnIndex == null) { textboxValue = "Column name \"" + columnNameOrIndex<#uniqueId> + "\" wasn't found."; } else if (columnIndex < 1) { textboxValue = "Column index cannot be lower than 1 (" + columnIndex + ")"; } else if (rowNumber<#uniqueId> < 1) { textboxValue = "Row number cannot be lower than 1 (" + rowNumber<#uniqueId> + ")"; } else if (datasetData.sheets[0].values.length < columnIndex) { if (defaultValue<#uniqueId> == null) { textboxValue = "Provided column index wasn't found in the dataset."; } else { textboxValue = defaultValue<#uniqueId>; } } else if (datasetData.sheets[0].values[0].length <= rowNumber<#uniqueId>) { if (defaultValue<#uniqueId> == null) { textboxValue = "Provided row number wasn't found in the dataset."; } else { textboxValue = defaultValue<#uniqueId>; } } else { textboxValue = datasetData.sheets[0].values[columnIndex - 1][rowNumber<#uniqueId>].value; } $("#container<#uniqueId>").text(textboxValue); } </script>