PDA

View Full Version : Using Grid Panel : Spring with extjs and JSON



namrata.rane
3 Mar 2010, 4:12 PM
I am an extjs newbie and I want to use data returned from a Spring controller in ext-js code to populate a GridPanel. Here is what happens :
- A page with a form gets submitted
- Spring MVC controller gets invoked
- the controller calls the service layer that returns a list
- this list needs to be displayed on UI using a extjs GridPanel
- The list is now apart of the model returned from controller

The question I have is how to access the data from the Spring model object in the ext-js code to define a GridPanel ?

Here is how I define the GridPanel




var myGrid = new Ext.grid.GridPanel({
store: myStore,
renderTo: 'myDiv',
columns: [
{header: 'UUID', width: 300, sortable: true, dataIndex: 'uniqueId'}
],
stripeRows: true,
height:350,
width:350,
frame:true,
title: 'List of Unique IDs'
});


I understand that the GridPanel would need a datastore. Note that this data store has all the data it needs on the client side, so there is no URL.

I tried to get the list data in JSON format in a hidden element
[listOfUniqueIDs] in the JSP and use it in the datastore like this:



var myStore = new Ext.data.JsonStore({
fields: [
'uniqueId', 'createdBy'
]
data : Ext.get('listOfUniqueIDs').getAttribute('value')
});


But it doesn't seem to get the data and the grid doesn't display anything.


Any ideas on how to get this data displayed ?

8 Mar 2010, 5:44 AM
try adding autoLoad : true to your data store config