☝️Small business or a startup? See if you qualify for our special offer.
+

Sample report by integrating with Data server

Answered
Gokuldas Chandgadkar asked on June 9, 2025

Hi,

I am trying to integrate our SQL data source with Flex monster using free trial. I have created simple project and trying to connect to  index created using Admin panel.

Here is the sample code. 

There is no clear example. So help to resolve will be appreciated.

Regards,

Gokul

 

Attachments:
sample.zip

9 answers

Public
Gokuldas Chandgadkar June 9, 2025

Hi, 

I have done some progress and managed to build my report for Balance sheet. Now I want to have common filter for branch and Datekey  for both sections. Please advise me how to achieve this.

Also how I can hide the filters shown for ACT_Level2, to ACT_Level4

Public
Maksym Diachenko Maksym Diachenko Flexmonster June 10, 2025

Hello, Gokul!

Thank you for your question.

We are glad to hear that you could create the necessary report layout. For implementing a shared report filter area for two tables, we recommend hiding the default filters for both tables by setting the showFilter and showReportFiltersArea grid options to false. Then, you can add a custom filter area with a single filter outside of Flexmonster. This filter area can be implemented in the following ways:

  1. Adding a custom filter handler, which would rely on the setFilter method to modify the filter configuration: https://jsfiddle.net/flexmonster/vms57Lyu/
  2. Using a button that would open Flexmonster's filter view using the openFilter API call: https://jsfiddle.net/flexmonster/wz6dh5yb/

The filters can be synced between the two tables using the reportchange event. This event will be triggered on every filter applied, allowing one to set a filter on a table when another is filtered. This approach would work independently of which field is used for filtering.

Please let us know if one of the approaches we have provided works for you.

Best regards,
Maksym

Public
Gokuldas Chandgadkar 2 days ago

Hi Maksym,

I tried to set the options as suggested. But it  just hides off-grid filters. My on-grid filters are still there.

Also I want to hide them on load and not on button click.

Please advise.

Regards,

Gokul

Public
Gokuldas Chandgadkar 2 days ago

Hi,

I also tried to setup code  for custom filter. But both pivot goes in circular refresh.

Public
Maksym Diachenko Maksym Diachenko Flexmonster 2 days ago

Hello, Gokul!

Thank you for your reply.

For your case, we recommend using the showFilter option. When set to false, this option hides the report filters area and removes filter buttons from header cells on the grid.
This option can be predefined in the report config to disable filters on load, as is shown in this JSFiddle: https://jsfiddle.net/flexmonster/a85t1fy0/

Regarding the infinite refresh loop, we appreciate you pointing this out to us. The syncing logic we provided does not account for working with asynchronous data sources like FDS, and is only viable for JSON or CSV data. We suggest removing the filter syncing from the second table, which is set in the reportchange event handler. This way, the filter would first be applied to one table, then set to another, without causing an infinite loop. Also, you could entirely remove the filter syncing and use the setFilter API call to set filter for both tables; however, this approach would only work when creating a custom filter handler.
Please check the fixed code samples:

We are looking forward to hearing your feedback.

Best Regards,
Maskym

Public
Gokuldas Chandgadkar 2 days ago

Hi Maskym,

Please find enclosed my attached  files

1. App.js

2. index2.html

3. flexmonster-config.json (For SQL indexes)

I have two issues constant refresh.  BR_Name filter drop down not populated

Attachments:
sample2.zip

Public
Gokuldas Chandgadkar 2 days ago

Hi,

I made it working  with some changes. But I want to avoid clicking on apply filter button. Is there any event such as 'filter applied' to sync the other grid? Below is my code

const fieldsForFilters = ["BR_NAME"]; // example fields

// Map field names to custom captions
const fieldCaptions = {
  BR_NAME: "Branch"
};

const filterButtonsContainer = document.getElementById("filter-buttons");

for (const field of fieldsForFilters) {
  const button = document.createElement("button");

  button.textContent = fieldCaptions[field] || field;
  button.style.marginRight = "10px";
  button.onclick = () => {
    pivot1.openFilter(field);
    // Do NOT sync here
  };
  filterButtonsContainer.appendChild(button);
}

// Create Apply button
const applyButton = document.createElement("button");
applyButton.textContent = "Apply Filters";
applyButton.onclick = () => {
  syncFilters(pivot1, pivot2); // Sync only once here
};
filterButtonsContainer.appendChild(applyButton);

Public
Gokuldas Chandgadkar 2 days ago

Also I had to modify syncfilter to avoid recursive calls

let isSyncing = false;

function syncFilters(pivotFrom, pivotTo) {
  if (isSyncing) return;
  isSyncing = true;

  pivotTo.off("reportchange");

  const hierarchies = pivotFrom.getAllHierarchies();
  hierarchies.forEach((item) => {
    const filter = pivotFrom.getFilter(item.uniqueName);
    if (filter) {
      pivotTo.setFilter(item.uniqueName, filter);
    }
  });

  // Reattach the listener after a short delay
  setTimeout(() => {
    pivotTo.on("reportchange", () => {
      syncFilters(pivotTo, pivotFrom);
    });
    isSyncing = false;
  }, 100);
}

Public
Maksym Diachenko Maksym Diachenko Flexmonster 15 hours ago

Hello, Gokul!

Thank you for sharing the code snippets.

We recommend adjusting the filter syncing logic to only transfer filter settings from the first to the second Flexmonster table to avoid using the second apply button. Based on your use case, this would be enough for implementing a single filter handler for two grids. The syncing logic between the two tables was only necessary if on-grid filters were used. If they are disabled, the complex syncing logic is redundant, and you can simply detect the change in one table with the reportchange event and pass it to another:

function interpolateFilter(pivotFrom, pivotTo) {
  const hierarchies = pivotFrom.getAllHierarchies()
  hierarchies.forEach((item) => {
    pivotTo.setFilter(item.uniqueName, pivotFrom.getFilter(item.uniqueName))
  })
}

We have also adjusted the previously provided JSFiddle example to include this change: https://jsfiddle.net/flexmonster/wz6dh5yb/
Note that this function is only called for the first table (see line 52 in JSFiddle):

reportchange: () => {
  interpolateFilter(pivot1, pivot2)
},

Please let us know if our answer helped you.

Best Regards,
Maksym

Please login or Register to Submit Answer