Dear visitor, despite all the challenges, our team continues operating at full speed.

We are ready to help with any questions you may have. Please fill out this quick form and we'll get back to you.

Fill the form
Get Free Trial

Getting a field property in the sorting method

Answered
Sergii Valko asked on June 10, 2020

Hello! Is any ability to retrieve field property(type = property) in the ‘flexmonster.sortingMethod’ comparator to may it possible to sort using some another value. Thank you in advance.

3 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 11, 2020

Hello,
 
Thank you for contacting us.
 
In order to use the member’s property while sorting the hierarchy using the sortingMethod, we suggest considering the following approach.
 
Get all members of the hierarchy using the getMembers API call. Next, filter the received array so that only two currently compared members are left. The resulting objects will contain the specified property and can be used in order to sort the hierarchy itself.
 
Please see an example we have prepared.
 
Our team wants to provide some explanation about the following code snippet taken from the mentioned sample. It is responsible for sorting itself:

flexmonster.on("reportcomplete", () => {
flexmonster.off("reportcomplete");
let members = flexmonster.getMembers("Tenure");
pivot.sortingMethod("Tenure", function(a, b) {
a = members.filter(function(member) {
return member.caption == a;
})[0];
b = members.filter(function(member) {
return member.caption == b;
})[0];
return a.properties.Sorting > b.properties.Sorting ? 1 : -1;
});
})

 
Execution of the sortingMethod is bound on the reportcomplete event. Also, members are written in the members variable as soon as the event is triggered.
 
After that, members are filtered and assigned to the a and b variables. Finally, 1 or -1 is returned based on the property of the chosen member.
 
Detailed information about used API calls and events can be found in our documentation:

 
Please let us know if it works for your case.
Do not hesitate to contact us in case additional questions occur.
 
Regards,
Illia

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 25, 2020

Hello, Sergii,
 
Our team is wondering whether the suggested approach was helpful for your case.
We are looking forward to hearing from you.
 
Regards,
Illia

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster July 9, 2020

Hello, Sergii,
 
We want to take an interest in whether our suggestion helped.
Our team is looking forward to hearing from you.
 
Regards,
Illia

Please login or Register to Submit Answer