0

Continuation from this post here

So i found out a way to keep the data without using cookies, where i sent it to the controller using Ajax.

Then in my controller, i defined the following, so that the prefs will persist within the controller even if the page changed

class MyController {
static prefs = [] as List

def index() {}
def list([prefs:prefs]) {}
def save() {}
def update() {}

def testPrefs() {
    def value = []
    def model = []
    def colNames = []
    def sortorder
    def sortname
    def grid
    def rows
    Map map = [:]

    map.value = params.'value[]'?.toString()
    map.model = params.'model[]'?.toString()
    map.column = params.'colNames[]'?.toString()
    map.sortorder = params.'sord'
    map.sortname = params.'sorn'
    map.grid = params.'grid'
    map.rows = params.'rows'
    prefs.add(map)
}
}

Where in the list page, it will retrieve the value of prefs

var prefs = "${prefs}";

But problem is, when i tried to retrieve the prefs on javascript, it gives me the following return

[{value=[a, b, c], model=[aa, bb, cc], column=[aaa, bbb, ccc, ddd], sortorder=desc, sortname=id, grid=#gridId, rows=50}]

instead of a JSON data.

Is it possible to read such data on Javascript? I tried getting prefs.value or prefs.sortorder but it shows undefined instead.

Thanks

Community
  • 1
  • 1
Fred A
  • 1,602
  • 1
  • 24
  • 41
  • You could try to use `var prefs = "${prefs as JSON}";` – wwarlock Jun 10 '14 at 11:31
  • Thanks for the input. I already abandoned the idea of passing data from JS to controller then back to JS through GSP. Instead i just work everything out at JqGrid level. Thanks again :) – Fred A Jun 13 '14 at 03:25

0 Answers0