Need a special offer?Find out if your project fits.
+

hide flat grid columns dynamically based on input column name

Answered
amir asked on October 10, 2020

I have a flat grid table. I have an array of strings (column names). On the basis of this array, I want to hide columns in the flat grid dynamically. User should also be able to show these hidden columns from field list
 
When I check slice object of the flat grid report it is categorizing fields into rows and measures. I suppose numbers and date type fields come under measures and rest (string, boolean and objects ) are categorised as rows . Please verify if this is the case

3 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster October 12, 2020

Hello,
 
Thank you for contacting us.
 
To display only chosen fields, include them in the Slice Object of your report. In this case, other fields present in the data set will be hidden from the grid and available from the Field List.
 
Concerning the categorizing.
Fields must be grouped by columns, rows, and measures in case pivot forms are used (compact/classic form). It serves to define the position of every hierarchy/measure on the grid.
 
In its turn, flat form does not depend on grouping. All fields chosen for columns, rows, or measures will be displayed on the grid one by one. Therefore, there are no specific rules which would regulate the fields categorizing in flat form.
 
Our team hopes it helps.
Please contact us if further assistance is needed.
 
Kind regards,
Illia

Public
amir October 16, 2020

That I know but my case was that I have the list of columns I want to hide. I have used a slice to show selected columns. But now i have the array of columns that i want to hide, Is this possible in flexmonster, or do I necessarily have to do this at my end to compute the columns that needs to be shown.
Regarding the categorization, I just wanted to know when flexmonster do categorization of fields into say columns and measure how do you decide which field goes in which category 
 
 
 
 

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster October 16, 2020

Hello,
 
Thank you for providing additional details.
 
We want to explain that Flexmonster shows only fields chosen to the slice.
In case no slice object is specified, and the flat form is used, Flexmonster displays all fields automatically.
 
To achieve the desired behavior (show all fields except hidden ones), we suggest using the following workaround:
Right after the reportcomplete event is triggered, get all available fields using the getAllHierarchies API call. Next, filter out the excluded fields and set the resulting slice using the runQuery method.
 
Please see the JSFiddle we prepared to demonstrate the described approach.
 
Also, we want to provide some additional explanations about the following code snippet used in the example:

let excluded = ["Size", "Color", "Country", "Price"]; //unique names of fields to exclude

flexmonster.on("reportcomplete", () => { //subscribe to the reportcomplete event
  flexmonster.off("reportcomplete"); //unsubscribe from the event (mandatory)
  let allFields = flexmonster.getAllHierarchies(); //get all fields
  let rows = []; //initialize the resulting set of fields
  for (let field of allFields) {
    if (!excluded.includes(field.uniqueName)) { //check whether the field is excluded or not
      rows.push({
        uniqueName: field.uniqueName
      });
    }
  }
  flexmonster.runQuery({ //run the resulting query
    rows: rows
  });
});

 
Concerning categorization.
Flexmonster groups fields automatically only in case no slice object is specified in the report.
In case flat form is chosen by default, all numeric and date fields will be added to measures, and the rest of the fields will be added to rows.
In case compact/classic form is used, the first numeric field occurred in the data set will be chosen to measures, and the first non-numeric one will be added to rows.
 
Please let us know if it helps.
Feel free to contact us in case further questions arise.
 
Best regards,
Illia

Please login or Register to Submit Answer