How can I specify which fields should be checked by default(visible in the grid) and which shouldn't for csv data in flat mode?
I have a csv data with over hundred fields(columns) but for default view I need to display only some of them. All fields should be available in the Fields popup so users can select more if they want. I was trying to set only fields which should be visible in slice.columns property, but it doesn't work.
Hi, Viktor!
Thank you for writing to us.
To specify certain fields to be shown on the grid, we recommend using the configuration of a flat table, similar to an example below:
https://jsfiddle.net/flexmonster/cwvzymfx/
Please let us know if everything works fine.
Best Regards,
Maksym
Hi there.
Is it possible to unselect a few fields without using slice.columns property?
Thanks
Hello, Tigran!
Thank you for reaching out to us.
Kindly note that it is possible to deselect fields in the Field List by setting the visible
property of the MappingObject to false
:
data: [
{
"Price": {
type: "number",
visible: false
},
},
{
"Price": 174
}
]
We have prepared a JSFiddle example for visualization: https://jsfiddle.net/flexmonster/92zmuw30/.
We also want to mention that the slice
is the main configuration property in Flexmonster.
Could you please tell us why the slice.columns
property is not suitable for you?
Looking forward to hearing from you.
Regards,
Solomiia
Hello Solomiia.
Thanks for answering.
If I use the visible property than that currect field won't be shown in FIELDS dropdown.
I just need to unselect it.
Slice.columns is not suitable for me because we often add fields dynamically (We take into account the data that we receive from the backend) . And many of these fields have their specific positions. If I use slice then the correct sequence of fields changes.
Hello, Tigran!
Thank you for the details about your use case.
Kindly note that it is only possible to include hierarchies to be shown on the grid.
However, we kindly suggest a workaround to deselect the necessary fields using getAllHierarchies() and runQuery() API calls along with reportcomplete event.
The idea lies in the following:
1. Create the Flexmonster instance without the slice
property. It will load all existing fields to the flat grid.
2. On the reportcomplete
event handler, get all available fields with getAllHierarchies()
API call:
flexmonster.on("reportcomplete", function() {
let allHierarchies = flexmonster.getAllHierarchies();
}
3. Filter from the resulting array the fields you don't want to be shown on the grid. For example, you can use the Array.prototype.filter()
method:
allHierarchies = allHierarchies.filter(/* filtering condition */);
4. Run the runQuery
with the resulting array in the columns
property:
flexmonster.runQuery({
columns: allHierarchies
});
We have prepared a JSFiddle example for visualization: https://jsfiddle.net/flexmonster/7cwntbs0/.
Hope you will find our answer helpful.
Please let us know if the suggested approach works for your case.
Regards,
Solomiia
Hello, Tigran!
Hope you are doing well.
Our team is wondering if you had a chance to try the suggested approach to exclude hierarchies using runQuery()
. Could you please let us know if it works for your case?
Looking forward to hearing from you.
Regards,
Solomiia
Hello, Tigran!
Hope you are having a great week.
Just checking in to ask if the suggested approach was helpful in deselecting the necessary fields from the Field List.
Looking forward to hearing your feedback.
Regards,
Solomiia
Hi Solomiia
Thanks for your help. Sorry for answering so late.
We very often add or remove dynamic fields using different filters (for example, after the selecting checkbox, we get the parameter from the backend and add this column). The only things I want to understand. Is it possible to have several fields as not selected by default or after adding dynamic fields.
Hello, Tigran,
Thank you for the response.
Kindly note that it is possible to choose which fields should not be selected, even if the fields in your data set are dynamically updated.
This behavior can be achieved by following the next steps:
This approach can be implemented using the getAllHierarchies() API call. This method would preserve the order of hierarchies from the original dataset.
You can implement the described approach if you know which fields should be unselected. Feel free to check the example in the following JSFiddle: https://jsfiddle.net/flexmonster/7cwntbs0/
Please let us know if such an approach would work for your case. Looking forward to hearing from you.
Kind regards,
Nadia
Hello Flexmonster team))
Thank you for the response. It works.
All the best.
Hello, Tigran!
Thank you for your feedback.
Our team is glad to hear that the suggested approach was helpful.
Feel free to contact us in case of any other questions.
Best regards,
Solomiia