Inquiry Regarding Applying Filters to Flexmonster Data Source

Answered
Mariusz Królikowski asked on August 7, 2023

Dear Flexmonster Support Team,
I hope this message finds you well. I am reaching out to inquire about the feasibility of embedding a filter within the dataSource configuration for a Flexmonster component implementation.
Currently, our configuration resembles the following:
 
dataSource: { type: "api", url: "https://fl.mydomain:9500", index: "xxxx", advanced: "TRUE" }
 
On the DataServer side, we have a JSON file serving as the data source. Our objective is to optimize data retrieval by incorporating a filter directly into the dataSource configuration. Specifically, we intend to retrieve only a subset of data that meets certain criteria, such as filtering by Year ("2020" in this case).
Could you please provide guidance on how to achieve this within the Flexmonster configuration? We would greatly appreciate your assistance in accomplishing this functionality.
Thank you for your time and support. Looking forward to your response.
 
 

7 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster August 7, 2023

Hello, Mariusz!
 
Thank you for reaching out to us.
 
Kindly note that prefiltering JSON data before passing it to Flexmonster using Flexmonster Data Server as a data source is possible only using the Data Server as a DLL.
The approach is the following:
 
1. Pass the filtering options to the server.
It can be done using requestHeaders parameter of the dataSource object:

dataSource: {
      type: "api",
    url: "https://fl.mydomain:9500",
      index: "xxxx",
      requestHeaders: {
           "filter_year": "2022",
            "filter_month": "July",
      }
}

You can also use the customizeAPIRequest:

let pivot = new Flexmonster({
  customizeAPIRequest: (req) => { req.requestHeaders = { "filter_year": "2022",
       "filter_month": "July", }; return req;
}
//other Flexmonster properties
}

 
2. On the server side, read the filtering details from the request headers and implement filtering.
Here is our step-to-step guide on the topic: https://www.flexmonster.com/doc/implementing-server-filter/.
 
You can find more details about using the Data Server as a DLL in our documentation section: https://www.flexmonster.com/doc/getting-started-with-data-server-dll/.
 
Please let us know if the described approach would work for your case.
 
Kind regards,
Solomiia

Public
Mariusz Królikowski August 7, 2023

i.e. DataServer must be installed on Windows, and it is possible under Linux?

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster August 8, 2023

Hello, Mariusz!
 
Thank you for your swift response.
 
Kindly note that the Data Server, implemented as a DLL, is cross-OS compatible. We used Visual Studio for Windows as IDE for our example, but you can use any other tool you like.
Please let us know if using Data Server as DLL can be the solution for your case.
 
Looking forward to hearing from you.
 
Regards,
Solomiia

Public
Mariusz Królikowski August 9, 2023

Thank you very much for your answer. We will try to deal with this problem. Although I admit that I was hoping that there was some simpler method of filtration. especially when 'index' in DataSever is a json file.

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster August 9, 2023

Hello, Mariusz!
 
Thank you for your feedback.
 
Kindly note that the approach of using FDS as a DLL allows to customize the Data Server functionality and implement additional features, such as server filters. For example, the Data Server's config is read at FDS startup, so features that are based on information provided during runtime should be specified differently, that's where the DLL approach is handy.

We also have a sample project available on GitHub showing how the server filter can be implemented: https://github.com/flexmonster/flexmonster-data-server-dll.
 
Do not hesitate to contact us if any further questions arise.
 
Kind regards,
Solomiia

Public
Mariusz Królikowski August 10, 2023

thx

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster August 23, 2023

Hello, Mariusz!

Hope you are doing well.

Our team is wondering if you had some time to try using Flexmonster Data Server as DLL. Could you please let us know if you have any further questions?

Looking forward to hearing your response.

Regards,
Solomiia

Please login or Register to Submit Answer