-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access Result data / Export Result Data to json format #154
Comments
I would also like to have access to the output data. I've been using |
I realized that you can use the
Here is what I got: const [tableState, setTableState] = useState(uiProps);
return (
<PivotTableUI
data={data}
onChange={(s) => {
setTableState(s);
}}
// whatever else you need
{...tableState}
/>
); and then the function: getFilteredRecords = () => {
const filtered = [];
if (tableState?.data) {
PivotData.forEachRecord(
tableState.data,
tableState.derivedAttributes,
(record) => {
const match = Object.keys(tableState.valueFilter).every((key) => {
// We are using !== true because PivotTable for some reason
// makes its filters in a way that the items included in the
// filter are the ones that are not included in the result
const recordValue = record[key];
return (
recordValue &&
tableState.valueFilter[key][recordValue] !== true
);
});
if (match) {
filtered.push(record);
}
},
);
}
return filtered;
} The return value will be an array with the data and derived attributes with filters applied. Not sure if it is the correct or the best way to do it, but worked for me. Of course, if you just want to get whatever is on the table (like the results of the aggregators) you can use the strategy I mentioned above of turning the table into a workbook using something like xlsx and just handle the data with the using the workbook. I did it like this: import { utils } from 'xlsx';
const getWorkbook = (selector) => {
const viewElement = document.querySelector('td.pvtOutput');
const table = viewElement?.firstElementChild;
if (table) {
return utils.table_to_book(table);
}
return utils.book_new();
}; |
Hi Team,
we want to convert the table generated by Pivot Table into Json Structure and want to save that data in the server.
Can you please guide , how we can access the result/output data or convert the output data into json form .
Regards,
Akash
The text was updated successfully, but these errors were encountered: