View Full Version : Have grid, have directstore, but data doesn't load

30 Jul 2009, 4:38 PM
The function runs now, but I don't understand how to get it to load into my grid, which also renders. A break point set in my server code confirms that the function was called, but I don't understand how to setup the grid to load the data after it is returned from the server.

function ForumInit()
if (typeof(KnowledgeBase.gridForumList) != "undefined") return;
gridStore = new Ext.data.DirectStore
directFn: DirectRequest.GetForumList,
paramsAsHash: false,
[B]paramOrder: '',
sortInfo: { field: 'ForumName', direction: 'ASC' },
idProperty: 'ForumID',
autoLoad: true,
{name: 'ForumID', type: 'string'},
{name: 'ForumName', type: 'string'},
{name: 'CreatedBy', type: 'string'},
{name: 'CreatedDate', type: 'date'},
{name: 'ForumType', type: 'string'},
{name: 'NumberOfPosts', type: 'int'},
{name: 'NumberOfThreads', type: 'int'},
{name: 'ForumCatId', type: 'int'},
{name: 'ModifiedBy', type: 'string'},
{name: 'ModifiedDate', type: 'date'}
remoteSort: false
KnowledgeBase.gridForumList = new Ext.grid.GridPanel
renderTo: 'divForum',
title: 'Forums',
frame: true,
viewConfig: { autoFill: true },
stripeRows: false,
scroll: false,
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
store: gridStore,
{header: 'Forum Name', dataIndex: 'ForumName', sortable: true},
{header: 'Created By', dataIndex: 'CreatedBy', width:140,
sortable: true},
{header: 'Created Date', dataIndex: 'CreatedDate', width: 90,
xtype: 'datecolumn', format: 'M d, Y', sortable: true},
{header: 'Type', dataIndex:'ForumType', width:50, sortable: true},
{header: 'Posts', dataIndex:'NumberOfPosts', width:50,
sortable: true},
{header: 'Threads', dataIndex:'NumberOfThreads', width:50,
sortable: true},
{header: 'Category', dataIndex:'ForumCatId', width:100,
sortable: true},
{header: 'Modified By', dataIndex:'ModifiedBy', width:140,
sortable: true},
{header: 'Modified Date', dataIndex:'ModifiedDate', width: 90,
xtype: 'datecolumn', format: 'M d, Y', sortable: true}

30 Jul 2009, 5:19 PM
First, if you don't define gridStore anywhere outside of the ForumInit() function, then use 'var' before it, otherwise you make it a global variable, and globals are evil.
Second, you don't need to specify paramsOrder:'' if you don't pass any parameters, just delete that line.
Third, try setting fixed height for your grid (for example height:500) and delete the line autoHeight:true (this is important, don't leave it there). Most likely this is why you don't see your data. It is probably there, but because the grid is too short you can't see it.

30 Jul 2009, 9:52 PM
It was just deleting the line paramOrder: '',
that fixed the problem, and this ForumInit() now replaces working but hacked up code that I was previously using for the same purpose. I also rewrote this to use a KnowledgeBase.Forum namespace for both the grid and the datastore.

Thanks for the help.

I wrote a lengthy document over the past few days for the internal developers here, and it would be a good get-started document for Ext.Direct for Asp.Net MVC. I actually start with a blank MVC project and gradually import the Ext.Direct and ExtJS libraries, add namespaces, and then add ExtJS elements and MVC views / Ext.Direct functions one at a time in a 20-page nicely formatted doc with screenshots.

(I have about 10 years of technical writing / technical document production experience so I know how to present complicated technical information. It also helps that I am also new to this, so I'm not glossing over anything.)

I will have to purge it of some overly specific stuff to my company, but it would be a good addition to elishnevsky's Ext.Direct example.

31 Jul 2009, 6:08 AM
I'm glad you finally solved this problem. It's always some little thing, isn't it.