PDA

View Full Version : Issue with JSON Data Store in ASP



Adamw
1 Mar 2010, 1:01 PM
I have been searching the ExtJS Forums and google to no resolution. I have a page that when a link is clicked from the West Panel Container a grid will populate in the center panel containing data from a MSSQL database query formatted in JSON.

The Grid renders however there is no data in the grid.

I tried to check the JSON data by including a standalone AJAX function inside the function the builds the store data.

From AJAX function:


{"total":2,"results":[{"Name":"Adam","Email":"[email protected]"},{"Name":"Adam","Email":"[email protected]"}]}
I do not know how to make sure that the JSON response to my Store is of the same format or even that anything was returned at all.


Does anyone know how to look into this? I am currently using Firebug to help debug my code but can not find the information that I am looking for.

Any help would be appreciated. Thank you.

evant
1 Mar 2010, 4:20 PM
1) When the store loads, what happens when you call the getCount method?

2) Have you specified dimensions on your grid? (Width/Height)

Adamw
1 Mar 2010, 8:14 PM
evant
1) When the store loads, what happens when you call the getCount method?

2) Have you specified dimensions on your grid? (Width/Height) 1) The getCount method returns 0

2) I specified
autoHeight: true
the widths are defined in colModel variable

Here is what I have so far:

Store info ( There is more to my ExtJS but wanted to keep it as simple as possible ):

// Create Json Data Store
store = new Ext.data.Store({
// store configs
//autoDestroy: true,
//storeId: 'myStore',
//id: 'DataStore',
proxy: new Ext.data.HttpProxy({
url: 'database.asp', //url to data object (server side script)
method: 'POST'
}),
baseParams: { view: id }, //this parameter is passed for any HTTP request
// reader configs
reader: myReader
}); // eo var store

// Load Data Store(s)
store.load;

// Create a Column Model
colModel = new Ext.grid.ColumnModel([
{
id: 'Name', //by placing an id on this column we can later reference the column specifically
header: 'Name', //header = text that appears at top of column
width: '10', //column width
sortable: true, //false (default) to disable sorting by this column
locked: false,
dataIndex: 'Name' //the DataStore field "name" this column draws its data from
},{
id: 'Email', //by placing an id on this column we can later reference the column specifically
header: 'E-mail', //header = text that appears at top of column
width: '10', //column width
sortable: true, //false (default) to disable sorting by this column
locked: false,
dataIndex: 'Email' //the DataStore field "name" this column draws its data from
}
]);

// Create Grid Panel
var grid = new Ext.grid.GridPanel({
store: store, //the DataStore object to use (ds: is shorthand)
colModel: colModel, //gets the ColumnModel object to use (cm: is shorthand)
autoheight: true, //you must specify height or autoHeight
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
el: 'center-region-container',
loadMask: true
});database.asp:

Function QueryToJSON(dbc, sql)
Dim rs, jsa, col
Set rs = dbc.Execute(sql)
Set jsa = jsArray()
While Not (rs.EOF Or rs.BOF)
Set jsa(null) = jsObject()
For Each col In rs.Fields
jsa(null)(col.Name) = col.Value
Next
rs.MoveNext
Wend
Set QueryToJSON = jsa
End Function

//' Initialization the Objects
Set Connect = Server.Createobject("ADODB.Connection")
Set oJSON = jsObject()

Connect.Open DSN,UN,PW

oJSON("total") = 0
Set oJSON("results") = QueryToJSON(Connect, SelectSQL)
oJSON("total") = oJSON("results").Count
//' Writes the Object out to the Response
//' toJSON(oJSON)
oJSON.Flush

evant
1 Mar 2010, 9:44 PM
store.load; // <--- ?????????????

Adamw
2 Mar 2010, 7:22 AM
Thanks Evant that was my trouble.

I replaced:

store.load;With this:

store.load();And now the grid is displaying data. Now to move on with my project.

Mike Robinson
2 Mar 2010, 8:02 AM
Welcome to JavaScript. :((

The only way to work rationally in this language is to use an editor that has a very strict and built-in "JavaScript lint" checker.

Paradoxically, what I am just saying is not a "blast" against the language. It is extremely powerful and allows you to do many things. But that power comes at a price. Many things are "syntactically valid," even nonsensical things. Furthermore, the language is designed to be interpreted in source-code form (compressed or no...) by each and every end user's computer. It can be baffling to deal with.