Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

How to have a custom sorted on field list?

Resolved
Sumukh asked on April 24, 2020

Hi Team,
We have a requirement at our side to separate out Measure(number) fields and the dimension(string) field. I understand that the fields right now are in alphabetical order. But is there a way to show string fields first and then number fields. Is there any workaround to change the sorting of field elements?
 
Regards.
 

2 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 24, 2020

Hello, Sumukh,
 
Thank you for your question.
 
We have prepared an example demonstrating one of the possible approaches to achieve the desired functionality. The list of hierarchies will be sorted in the following way: hierarchies which are not considered as measures (string data type) will be placed first in alphabetical order. After them, all measures (number data type) will be displayed. They will be sorted in alphabetical order as well.
 
Our team would like to provide some additional explanation about the following code snippet responsible for sorting hierarchies in the desired way:

pivot.on("fieldslistopen", () => {
let temporary = [];
setTimeout(() => {
let fieldList = document.querySelector("#fm-lst-hierarchies");
for (let i = 0; i < fieldList.childNodes.length; i++)
for (let singleClass of fieldList.childNodes[i].classList)
if (singleClass == "fm-measure") {
temporary.push(fieldList.childNodes[i]);
fieldList.removeChild(fieldList.childNodes[i]);
i--;
}
for (let field of temporary)
fieldList.appendChild(field);
}, 0);
});

 
It is executed after the fieldlistopen event is triggered.
The list of all hierarchies can be received through the following selector: "#fm-lst-hierarchies". Next, all child nodes of the list are checked and the ones containing the "fm-measure" class are removed from the list. Such elements are saved in the temporary array and appended back to the list after filtering is finished. They are appended to the end of the list keeping an alphabetical order.
Please note that setTimeour should be set in order to make sure that the element is created after the Field List is opened.
Detailed information about the fieldlistopen event can be found in our documentation.
 
We sure hope it works fine for your case.
Please contact us in case of additional questions.
 
Best regards,
Illia

Public
Sumukh April 25, 2020

That was quick and in detail. Highly appreciated.
Thank you. 

Please login or Register to Submit Answer