Data source complex filtering


(Sean) #1

Hi all

Hoping someone might have some ideas on how to get more advanced filtering of a data source.

Scenario we need is as follows:

We have a JSON data source asset that hits an API endpoint and grabs all the data.
Example data set would be:

  • Item-number
  • Item-name
  • Item-content
  • Item-status
  • Item-date

The user would have the option to search/filter on the following at the same time

    • Item-Status - User can select any/all of 3 form check boxes on the front end which would then “Match on any condition” of the 3 possible status’s so will broaden the results the more check boxes that are selected.
    • Item-name and Item-content - User enters values into form input fields for name and content on the front end which would “Match on all conditions” and therefore narrow down the results the more information that is entered.
    • Item-date - User enters/selects one or both of start-date and end-date on the front end which would match any Item-date that falls between these dates

I can do 1 and 2 in isolation but there doesn’t seem to be a way to do both at the same time with record filters.
And I’m not sure 3 is possible at all.

Any idea if some/all of this is possible a different way or with SSJS possibly?

Thanks


(Iain Simmons) #2

You could do this all in SSJS or a REST asset using regular array methods, but depending on your needs for displaying on the front-end, it might be easier and a better experience for the user to just use something like DataTables and fetch the API data, then use configuration and plugins to enable the kinds of filtering you require.

I believe DataTables was using Moment for date filtering, but depending on the kind of value the source data has, you might be able to just convert it to a UNIX timestamp and then do the same for the start and end date ranges and compare the integers with less than and greater than.

Hope that helps!


(Sean) #3

Thanks for the reply.
Could you elaborate a little more on the second option?
What do you mean by DataTables and plugins?

The dates are already just a UNIX timestamp but using a JSON data source asset and standard filtering there doesn’t seem to be a way to use greater/less than.

Cheers


(Bart Banda) #4

Yeah I would try and do it all with client-side JS and using something like https://datatables.net/