(Click to open topic with navigation)
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
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}"}, ...
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.
nodes = """{
"sort" : {"${DV_SORT_SORT}":[{"states.state":"DESC"}]},
...
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