Hi,
I am in the process of integrating extJS with Grails.
Below is my list action in my music.TuneController.
def list = {
def tuneInstanceList = new ArrayList<Tune>()
def tune= new Tune();
tune.playerId = "ASDF";
tune.playerPrice= "100";
tuneInstanceList.add(tune);
def listResult = [ total: tuneInstanceList.size(), items: tuneInstanceList]
render listResult as JSON
}
My code in tune-grid.js
/*
* Ext JS Library 2.0 Beta 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* [email protected]
*
* http://extjs.com/license
*/
Ext.onReady(function(){
// create the Data Store
var ds = new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'http://localhost:8080/music'}),
reader: new Ext.data.JsonReader({
results: 'total',
root:'items',
id:'id'
},
[
{name: 'playerId' },
{name: 'playerPrice'}
]
)
});
var cm = new Ext.grid.ColumnModel([
{header: "Player Id", width: 120, dataIndex: playerId },
{header: "Player Price", width: 180, dataIndex: 'playerPrice'}
]);
cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.GridPanel({
ds: ds,
cm: cm,
renderTo:'grid-example',
width:540,
height:200
});
});
list.gsp:
<%@ page import="music.Tune"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="test" />
<g:set var="entityName" value="${message(code: 'song.label', default: 'Song')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
<g:javascript library="tune-grid"/>
</head>
<body>
<div class="body">
<!--<g:javascript library="examples"/>-->
<!-- EXAMPLES -->
<div id="grid-example"></div>
</div>
</body>
</html>
When the action is called , I get the below as the output. It seems that the control doesnt get to the list.gsp at all.
{"total":1,"items":[{"class":"music.Tune","playerId":"ASDF", playerPrice":"100","playerDep":null}]}
Could you tell me what I am doing wrong here?
Thanks!