UI-Table download/export filtered data on columns

Hi,

I successfully added filters to the columns of my table, but now I want to be able to download the filtered data as CSV or just get the filtered data and create myself the CSV file.
image

I think one of these 3 options suits me (in order of preference):

  1. Call the built-in download/export function using the template node. But I have no idea how to call functions of the ui table.
  2. Send a command to request all visible data, if even exists. The quick info documentation only shows 3 commands. Where can I find the list of commands?
  3. Have a callback function when the filters are applied. If someone has an example it would be great.

Any help?
Thanks in advance.

Only a quick answer to your point 2.
All you can do (commands, callbacks, parameters ...) are well documented @ tabulator website.
ui-table only acts as an interface.
I think everything you can do with tabulator should be doable through ui-table

Tabulator allows you to download/export the table data as a file directly from your browser, no server needed.

The download will contain the text values of all data currently visible in the table, matching the current column layout, column titles, sorting and filtering.

Hope this functionality already exists in 3.7 which is the version ui-table currently use.

To 1.
I would use a normal dashboard button and send a command to ui-table to trigger the export function.

See the commands part in the ui-table readme to know more about formatting the message to ui-table

And finally to 3.

Where can I find the export function command? The readme file only mentions addRow, replaceData or addFilter and says:

Beside data manipulation you can set filters and do many other things with commands.

I have tried sending commands getData, getFilters, getHeaderFilters and none of them works. I still don't know where to find the list if the supported commands, I am just assuming they are the names of the available functions.

Adding the callback function gives the error InternalError: too much recursion on the browser console and my data is fails to load. This is the callback definition I added to msg.ui_control.tabulator:

dataFiltered: "function(filters, rows){this.send({ui_control:{callback:'dataFiltered'}, filters: filters, rows: rows}); }",

As mentioned here

Rows is a component and can‘t be converted into a JSON string to be sent from the frontend to the backend (node-red)

You have to use the methods to pic the data items.

table.download("csv", "data.csv"); //download table data as a CSV formatted file with a file name of data.csv

As described in the tabulator doc I linked before:

And the ui-table readme and the examples how to build the message to be sent to ui-table

Thanks for the hints. Sorry for my lack of knowledge in JavaScript/NodeJS stuff.

I now have access to the data, but my requirements changed a little and now I need the applied filters. The problem is that the 'filters' parameter on the 'dataFiltered' and 'dataFiltering' callbacks are always zero length arrays. I inspected the 'rows' parameter but couldn't find the applied filters either. Am I doing something wrong?

image

Just found the get filters method from the rows elements.
rows[0]._row.table.getHeaderFilters()
My programming experience tells me this is not a good practice, but my ignorance in JS makes me doubt about my first assumption.

Hi,

sorry I do not have time to dig in deeper. Accessing prototype properties (_) directly is not "best practice", because if the implementations changes in the future you have the risk that your code could be broken. Best is to find a get method to access the properties you need.

Chris

this is the far i could understand on how to build the message to be sent to ui-table
msg.ui_control = {
"tabulator":{
"command":"download",
"arguments":[
{
"type": "csv",
"name": "feeder41.csv"
}
]
}
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.