# How can I save uiState in a Visualization?

**URL:** <https://discuss.elastic.co/t/how-can-i-save-uistate-in-a-visualization/71671>\
**Category:** Kibana\
**Created:** [January 16, 2017, 4:46am UTC](https://discuss.elastic.co/t/how-can-i-save-uistate-in-a-visualization/71671 "2017-01-16T04:46:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![YYtea](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@YYtea](https://discuss.elastic.co/u/YYtea)\
**Post date:** [January 16, 2017, 4:46am UTC](https://discuss.elastic.co/t/how-can-i-save-uistate-in-a-visualization/71671/1 "2017-01-16T04:46:21Z")

</div>

I am writing a new Visualization plugin for kibana 5.1.  
And I want to save the ui config object into uiStateJSON.

```auto
config: {
  rows: [],
  cols: [],
  aggregatorName: "Count",
  vals: []
},

```

tried `$scope.uiState=$scope.table.config;` in controller  
but it does not work.

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [January 17, 2017, 12:25am UTC](https://discuss.elastic.co/t/how-can-i-save-uistate-in-a-visualization/71671/2 "2017-01-17T00:25:17Z")

</div>

The `uiState` object has `get` and `set` methods that you should use to read/write data on it. It will be easier if you also use it as your single source of data:

```auto
uiModule.controller('MyController', class {
  constructor($scope) {
    /* read the rows from the uiState, or return the default (an empty array) */
    this.getRows = () => $scope.uiState.get('rows', [])

    /* change the rows saved in the uiState */
    this.setRows = (newRows) => $scope.uiState.set('rows', newRows)
  }

  /* add an empty row to the end of the row state */
  addEmptyRow() {
    this.setRows(this.getRows().concat([]))
  }

  /* delete the last row in the row state */
  removeLastRow() {
    this.setRows(this.getRows().slice(0, -1))
  }
})

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 14, 2017, 12:25am UTC](https://discuss.elastic.co/t/how-can-i-save-uistate-in-a-visualization/71671/3 "2017-02-14T00:25:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
