How can I access the data in a table that has filters applied?

Hello everyone! I am using the new table component and I want to have a button to download what is in the table, I know that the table natively you can add a toolbar button to download what is in the table but what it does is simply use the export method of the table to download a file, which does not work for what I need because it exports the data with a different format than I need. So I need to have a way to access the data that is in the table to format it and then download it, from what I saw you can only access the data property of the table but when applying a filter I can not find a way to access that data, any idea how to do it?

1 Like

use a Query with JSON resource
then you can select * from {{yourtable.data}}

@ScottR But it still returns ALL the data, not the data that is filtered in the table.

The only way to get the data remaining after it is filtered would be to store the filtered data in a temp variable and query that....

@ScottR Ok, but the doubt remains, what are you going to save in the temporary variable ? how will you access the filtered data to save it in the variable ?

@Kabirdas @Tess @victoria any help? I debug the table object find there is not any method to get the filtered table rows? the table1.setFilterStack(some parameter) don't return the the filtered rows either.

can you consider this feature request - add function or a property of table to keep the filtered rows?

2 Likes

Hi there! There is a feature request for this, and I'll post here if our team is able to ship a fix

In the meantime, you'd have to write some custom code using the filterStack property to return the filtered results

Here's an example Javascript query that returns filtered data based on the table's filterStack. Please note, this does not account for every data type/edge case, but this should help to give an idea of what could work

let filters =  table1.filterStack.filters
let method = table1.filterStack.operator ==='and' ? 'every' : 'some'

function applyFilter(inputArray, filters, method) {
  return inputArray.filter(item => {
   
      return filters[method](filter => {
      const { operator, value, columnId } = filter;
      const itemValue = item[columnId];
      switch (operator) {
        case '<':
          return itemValue < value;
        case '>':
          return itemValue > value;
        case '<=':
          return itemValue <= value;
        case '>=':
          return itemValue >= value;
        case '=':
          return itemValue === value;
        case '!=':
          return itemValue !== value;
        case 'is empty': 
          return itemValue;
        case 'is not empty': 
          return itemValue;
        case 'isTrue': 
          return itemValue;
        case 'isFalse': 
          return !itemValue;      
        default:
          return false;
      }
    });
  });
}
return applyFilter(table, filters, method)

I second this request. I'd love to get a list of ID's that pass the filterStack conditions, instead of having to JS my away around to re-apply the filtering with those filterStack conditions, which will always be a sub-optimal job, because, as mentioned, there are a lot of edge cases.

Cheers

Any news on this feature request?

Not yet :disappointed: but I'll post here if I hear anything internally

I used your provided code to emulate the display data for the new tables, but the filterStack property seems to only update from added or cleared filters if the table is currently visible within a tabbed container. Do you have a recommendation to get around this issue and would it be possible for it to be fixed?

Hi @Daniel_Fleuranvil Interesting :thinking: I see what you mean. I'll request for this to be fixed-- thanks!

1 Like

This wont work work with server side pagination right?

Hi there! We have now shipped a feature for getting the displayed data of a table :blush:

If the table is paginated, it'll return a single page. The filter UI feature doesn't work with pagination

2 Likes

The bug where the filterStack only updates when the table is visible is still in our queue

1 Like

This solved all of my problems, thanks so much! Was able to use this to dynamically update a graph.

2 Likes