Adding Calculated Value inline code

Answered
David Chen asked on March 1, 2016

Can anyone create a jsfiddle showing up to create a calculated field
for example

var report = {
configuratorActive: false,
data: jsondata,
rows: [{uniqueName: "Color"}],
columns: [{uniqueName: "[Measures]"}],
measures: [{uniqueName: "Price"}, {uniqueName: "Quantity"}],
addCalculatedValue: [......]

formats: [{name: "", nullValue: "blank"}],
showHeaders: false
};
report.licens.....

6 answers

Public
Iryna Kulchytska Iryna Kulchytska Flexmonster March 1, 2016

Hello David,

Here is a jsfiddle that addresses your question: https://jsfiddle.net/irynakulchytska/zmqzspng/6/
Calculated fields go in 'measures' array with all the measures, as follows:
 
measures: [{uniqueName: "Price", aggregation: "average", availableAggregations: ["average"], active: true}, {uniqueName: "Quantity", aggregation: "average", availableAggregations: ["average"]}, {uniqueName: "Formula #1", caption: "Formula #1", calculated: true, formula: "sum('Price') / sum('Quantity')", active: true}]
 
Kind regards,
Iryna

Public
David Chen March 1, 2016

Thanks. How do I sort a variable in the column descending?

Public
Iryna Kulchytska Iryna Kulchytska Flexmonster March 1, 2016

Hi David,
 
You can sort values in some column by specifying measure, tuple and type in columnSorting property as follows:

columnSorting: {measure: "Price", tuple: "", type: "desc"}

Here is a jsfiddle: https://jsfiddle.net/irynakulchytska/zmqzspng/7/
 
Please let me know if it is what you are looking for.
 
Kind regards,
Iryna

Public
David Chen March 1, 2016

so if I want to sort Color first then another row, it would be
 

columnSorting: [ {measure: "SortFirstVariable", tuple: "", type: "desc"},{measure: "ThenSortSecondVariable", tuple: "", type: "desc"} ]
Public
Iryna Kulchytska Iryna Kulchytska Flexmonster March 1, 2016

David,
 
Thank you for your question.
 
If you want to sort colors in Color field, then you can do this from report object the following way: https://jsfiddle.net/irynakulchytska/zmqzspng/8/

rows: [{uniqueName: "Color", sortName: "desc"}]

The previous example is about the case when you want to sort numbers in columns on the grid. 
 
Also, please note that the sorting can be done from UI. Then you can call flexmonster.getReport() API call to get the report object with all the settings and you can examine it to find out how the change from UI is stored in the report object.
 
Please let me know if you need more clarifications.
 
Kind regards,
Iryna 

Public
Tanya Gryshko Tanya Gryshko Flexmonster December 12, 2016

Hello David and all Flexmonster users,
This updated sample shows how to create a calculated field in version 2.3: https://jsfiddle.net/flexmonster/ve4hp3ez/.
Starting from version 2.3, the structure of Report Object was changed. columnSorting property was renamed to slice.sorting.column. Descending sorting for a variable in the column is defined the following way:

sorting: {
    column: {measure: "Price", tuple: "", type: "desc"}
}

Open in JSFiddle: https://jsfiddle.net/flexmonster/3pjoqhsf/.
sortName property was renamed to sort. Sorting colors in Color field should be defined like this:

rows: [{uniqueName: "Color", sort: "desc"}]

Please check the updated sample:
https://jsfiddle.net/flexmonster/4j9ndacf/
Find more details about the new structure of Report Object in the documentation: http://www.flexmonster.com/api/report-object/
Regards,
Tanya

Please login or Register to Submit Answer