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

Configuring the default sort

The DataviewConfig.groovy file is set up so that when a Viewpoint DataView page first loads, the items in the list sort a certain way—usually by the first visible column. However, you can cause the page to sort by default on any column you wish. These instructions explain how to change the default sort option in the DataviewConfig.groovy file.

To change the default sort setting

  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 "sort" element.
  3. nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"name":"ASC"}]},
    "page" : {"${DV_PAGE_NUMBER}":0, "${DV_PAGE_COUNT}":20},
    "filter" : "{}",
    ...

    The sort element, "${DV_SORT_SORT}", is set to the "${DV_DBKEY_KEY}" value for the column you want to sort by. Note that if no "${DV_DBKEY_KEY}" is present, the sort element is set to the "${DV_ID_KEY}" value. For example, there is no "${DV_DBKEY_KEY}" value for the "Name" column on the Node Management page, so the sort element is set to the "${DV_ID_KEY}" ("name").

    nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"name":"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}"},
    ...
  4. Change the value for "${DV_SORT_SORT}" to the "${DV_DBKEY_KEY}" (or, if it is not present, to the "${DV_ID_KEY}") value for the column you want to sort by.
  5. For example, if on the Node Management page you want to sort by the "Status" column, change the value to "states.state".

    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"},
    ...

    Make sure that the column you sort by is marked as sortable. The "${DV_SORTABLE_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 sortable.

  6. Specify the default order you want to sort by. Specify "ASC" for ascending, or "DESC" for descending alpha-numeric order. For example, to sort by descending order:
  7. nodes = """{
    "sort" : {"${DV_SORT_SORT}":[{"states.state":"DESC"}]},
    ...
  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