Greetings.
We work with Vue 3 composition api.
In this code we have:
pivotConfig our saved reportObject configuration in localStorage ( in this case only report.slice)
Our problem starts in watch(props.data).
We have this problem only if get empty data from server.
if we always load ( not empty ) data, all work's fine. And don't delete our .slice
Is it bug ? Or wo don't understand something ?
Extra question. How to set globalObject ? Fox example globalObject.localization ?
Do we have something like gerReport() and setReport() for globalObject ?
Thank you for your reply.
<template> <Pivot ref="pivot" toolbar v-bind:licenseKey="'key'" /> </template> <script setup> import Pivot from "vue-flexmonster/vue3"; import "flexmonster/flexmonster.css"; import { ref, watch, defineProps, onMounted } from "vue"; let pivot = ref(); let pivotConfig = JSON.parse(localStorage.getItem("pivot-report-config")) || {}; // Define props const props = defineProps({ data: { type: Array, required: true, }, }); onMounted(() => { pivot.value.flexmonster.setReport({ localization: "/locale/flexmonster_lt.json", }); }); watch( () => props.data, (newData) => { const report = pivot.value.flexmonster.getReport(); if (report) { console.log("start1"); pivot.value.flexmonster.updateData({ data: newData }); } else if (!report) { console.log("start2"); pivot.value.flexmonster.setReport({ dataSource: { data: newData, }, slice: pivotConfig.slice, }); } }, { deep: true } ); </script>
Hello, Robert!
Thank you for reaching out to us.
Kindly note that the slice in Flexmonster needs to know which fields would be present in the data source, and usually it takes these fields from the dataSource object. When the updated report.dataSource
object is empty, the report.slice
has no reference for the field names, so it clears itself and resets to the default one on the next update.
We recommend adding a mapping
to your dataSource
object to ensure the slice always knows which fields should be present in the data source, even if the current data is empty. You can read more about mapping in our guide: https://www.flexmonster.com/doc/mapping/.
Here is the JSFiddle to illustrate how Flexmonster with defined mapping handles the empty data update: https://jsfiddle.net/flexmonster/93zma2f0/.
Hope you will find our answer helpful.
Kind regards,
Solomiia
Hello, Robert!
Hope you are doing well.
Our team is wondering if you had some time to try updating empty data with defined mapping. Could you please let us know if the suggested approach was helpful?
Looking forward to hearing from you.
Kind regards,
Solomiia
Hello, Solomiia!
Thank you for your reply.
Yes, your solution solved our problem and helped us to understand better how flexmonster works.
Hello, Robert!
Thank you for your feedback.
We are glad to hear our answer was helpful.
Feel free to reach out to us if any other questions arise.
Kind regards,
Solomiia