You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Access Result data / Export Result Data to json format #154
I would also like to have access to the output data.
I've been using document.querySelector('td.pvtOutput') to get the table and then turning that into a workbook. The problem is that it only gives me the values currently being displayed on the table, I would like to have access to the entire data of the rows that are present after applying the filters.
forEachMatchingRecord takes a criteria that is based on a key value structure, so you can't really apply the same filters you might be applying to the pivot table — as far as I can tell, at least — which is why you might wanna use forEachRecord.
Here is what I got:
const[tableState,setTableState]=useState(uiProps);return(<PivotTableUIdata={data}onChange={(s)=>{setTableState(s);}}// whatever else you need{...tableState}/>);
and then the function:
getFilteredRecords=()=>{constfiltered=[];if(tableState?.data){PivotData.forEachRecord(tableState.data,tableState.derivedAttributes,(record)=>{constmatch=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 resultconstrecordValue=record[key];return(recordValue&&tableState.valueFilter[key][recordValue]!==true);});if(match){filtered.push(record);}},);}returnfiltered;}
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. PivotData seems to be pretty useful, would be nice if it was covered on the docs.
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:
Activity
luizppa commentedon Feb 13, 2024
I would also like to have access to the output data.
I've been using
document.querySelector('td.pvtOutput')to get the table and then turning that into a workbook. The problem is that it only gives me the values currently being displayed on the table, I would like to have access to the entire data of the rows that are present after applying the filters.luizppa commentedon Feb 14, 2024
I realized that you can use the
PivotDataclass to achieve that. I experimented using two available functions:forEachMatchingRecordandforEachRecord.forEachMatchingRecordtakes a criteria that is based on a key value structure, so you can't really apply the same filters you might be applying to the pivot table — as far as I can tell, at least — which is why you might wanna useforEachRecord.Here is what I got:
and then the function:
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.
PivotDataseems to be pretty useful, would be nice if it was covered on the docs.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: