Core API

Filter

Filter is the important entities of GudHub. It is responsible for the sorting and structuring data.

There are several items that have filter: table, . Some of them use it inside the code, others allows to use it in the application. The programmer decides which item will have the filter.

Every data that display items has its own filtering set. The filtration takes field values for finding and selecting needed data. Also, you can configure filter for different fields and select the type of the filtration.

The filter accepts different types of search values (string, number etc.) and can be applied for different types of fields.

It accepts two arrays as arguments:

import GudHub from '@gudhub/core';
const gudhub = await new GudHub();
let items = [{
  "item_id": 2987986,
  "fields": [{
        "element_id": 645888,
        "field_value": "John",
      }],
  },
  {
  "item_id": 2987996,
  "fields": [{
        "element_id": 645888,
        "field_value": "Johana",
      }]
  }
]

let filter_list = [{
    "data_type": "text",
    "field_id": 645888,
    "search_type": "search",
    "selected_search_option_variable": "Value",
    "valuesArray": ["john"]
    }
]

gudhub.filter(items, filter_list)
Name Type Description
items array array of items which will be filtered
filter_list array array of filters which will be applied to items

Filter is not applied without search values.

Filter allows you to add several filters for the same item at the same time. In turn, the fields can have only one filter. But, as fields can contain multiple value, filters can search for a few ones.

As for filters JSON, all filters data is contained in filters_list which in turn located in the certain item. For example:

filters_list: [{
    "data_type": "text",
    "field_id": 603733,
    "search_type": "contain_or",
    "selected_search_option_variable": "Value",
    "valuesArray": ["field value",...],
},...]

As you can see, filters_list consists of the filter object. If there is no filter in item, list is empty.

Name Type Description
filter_list array array of object with data about filtering
data_type string contains the values type
field_list number contains ID of the field that is being filtered
search_type string contains the type of searching
selected_search_option_variable string allows to add environment value
valuesArray array contains all values, by which filtering is carried out

Search Types

The filter can accept multiple values for searching at the same time. For comfortable filtering you can choose on what basis the filter will select the fields. For example, you want to get all results that contain you value or on the contrary all results without your value. So, you can configure filter for such needs due to search_type. It has a large range of values:

  • contain_or
  • contain_and
  • not_contain_or
  • not_contain_and
  • equal_or
  • equal_and
  • not_equal_or
  • not_equal_and
  • phone_equal_or
  • distance
  • search
  • bigger
  • lower
  • range
  • date_in
  • date_out
  • value

For convenience, we can divide some of them into groups:

  1. Contains
  2. Equals
  3. Number filters
  4. Date filters

The rest of filters will be described separately.

All details about them you can read in the next chapters.