You are here: 1 – Setup > 1.4 Viewpoint customization > Customizing Viewpoint with the DataviewConfig.groovy file > Configuring the default filter

Configuring the default filter

By default, there is no filter applied on any DataView page when it loads. The filter functionality more or less filters out items so that only those that match a certain criteria display. For example, a user can go to the Node Management page and see a list of all nodes. However, maybe the user only wants to see nodes that have a status of "Down." The user can do a search (which is essentially a filter) for nodes that are "Down" so that only those nodes display in the list.

You can configure the DataviewConfig.groovy file so that a default filter is applied to a page when it loads. Filtering uses a syntax that allows direct queries on the underlying MongoDB in MWS. Filters filter on the data contained in the MongoDB.

For information about MongoDB advanced queries, see the MongoDB documentation. For information about querying MWS, see their Resource documentation.

To configure the default filter

  1. Open the DataviewConfig.groovy file in the $VIEWPOINT_HOME directory, and find the ID of the page you want to modify (for example, if you want to modify the Node Management page, find the nodes section).
  2. Locate the "filter" element.
  3. nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"name":"ASC"}]},
    "page" : {"${DV_PAGE_NUMBER}":0, "${DV_PAGE_COUNT}":20},
    "filter" : "{}",
    ...
  4. If the DataView page uses a simple filter (all DataView pages except for the Service Management page use a simple filter), enter the query for the filter. For example, if you want to filter the Node Management page so that only nodes with a status of "down" display, enter the following query:
  5. nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"name":"ASC"}]},
    "page" : {"${DV_PAGE_NUMBER}":0, "${DV_PAGE_COUNT}":20},
    "filter" : "{
        "query": {
            "states.state": {
                "$regex": "down",
                "$options": "i"
            }
        }
    }",
    ...

    Make sure that the column you sort by is marked as filterable. The "${DV_FILTERABLE_KEY}" value should be set to 1 (true). For example:

    nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"states.state":"ASC"}]},
    "page" : {"${DV_PAGE_NUMBER}":0, "${DV_PAGE_COUNT}":20},
    "filter" : "{}",
    "data" : {
        "view":[
          {"${DV_ID_KEY}": "name",            "${DV_TITLE_KEY}": "Name",     "${DV_VISIBLE_KEY}": 1,  "${DV_SORTABLE_KEY}": 1, "${DV_FILTERABLE_KEY}": 1,  "${DV_TYPE_KEY}": "${DV_STRING_TYPE}"},
          {"${DV_ID_KEY}": "state",           "${DV_TITLE_KEY}": "Status",   "${DV_VISIBLE_KEY}": 1,  "${DV_SORTABLE_KEY}": 1, "${DV_FILTERABLE_KEY}": 1,  "${DV_TYPE_KEY}": "${DV_STRING_TYPE}", "${DV_DBKEY_KEY}": "states.state"},
    ...

    For more information, see Making columns filterable.

  6. If the DataView page uses a faceted filter (only the Service Management page uses a faceted filter), enter the query for the filter. For example, if you want to filter the Service Management page so that only services owned by "admin" with a status of "scheduled" display, enter the following query:
  7. job = """{
    "sort" : {"${DV_SORT_SORT}":[{"name":"ASC"}]},
    "page" : {"${DV_PAGE_NUMBER}":0, "${DV_PAGE_COUNT}":20},
    "filter" : "{
        "facets": [
            {
                "caption": "user contains admin",
                "query": {
                    "user": {
                        "$regex": "admin",
                        "$options": "i"
                    }
                }
            },
            {
                "caption": "status contains scheduled",
                "query": {
                    "status": {
                        "$regex": "scheduled",
                        "$options": "i"
                    }
                }
            }
        ]
    }
    ...
  8. Save your changes to the DataviewConfig.groovy file.
  9. Go to the Configuration Home page in Viewpoint, and verify that your JSON syntax is still correctly validated. For more information, see Fields: Configuration Home.

Your changes should update automatically. However, if you see that your changes have not taken effect, it is recommended that you restart Tomcat.

Related topics 

© 2015 Adaptive Computing