Ext生成GridView的CodeSmith模板

<%-- 
Name:
<%= GetClassName(SourceTable) %>
Author: sunfishlu
Description: 
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="JScript" Description="Generates a very simple business object." ResponseEncoding="UTF-8" %>
<%@ Property Name="NameSpace" Type="String" Category="Text" Default="Sunfishlu." Description="The namespace to use for this class" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>

/**
 * @author sunfish
 
*/


var storeMain 
= new Ext.data.Store({
    proxy:
new Ext.data.HttpProxy({
        url:
'<%= GetUrlName(SourceTable) %>'
    }
),
    reader:
new Ext.data.JsonReader({
        root:
'data',
        id:
'<%= SourceTable.PrimaryKey.MemberColumns[0].Name %>',
        totalProperty:
'totalCount',
        fields:
        [
            
<% for (int i=0; i < SourceTable.Columns.Count; ++i) %> <%=GetMemberVariableName(SourceTable.Columns[i])%><% if (i < SourceTable.Columns.Count - 1%>,<% }%><%}%>
        ]
    }
),
    remoteSort:
true
}
);

Ext.onReady(function()
{
    Ext.BLANK_IMAGE_URL 
= 'http://images.cnblogs.com/s.gif';
    Ext.QuickTips.init();
    var grid 
= new Ext.grid.GridPanel({
        store:storeMain,
        columns:
        [
            
new Ext.grid.RowNumberer(),
            
            
<% for (int i = 0; i < SourceTable.Columns.Count; i++%>
            
{header:"<%=GetHeaderName(SourceTable.Columns[i])%>",align:'center',sortable: true,dataIndex:<%=GetMemberVariableName(SourceTable.Columns[i])%>}<% if (i < SourceTable.Columns.Count - 1%>,<% } %>                
            
<% }
 %>
        ],
        renderTo:
'grid',
        viewConfig:
{forceFit:true},        
        trackMouseOver:
true,
        loadMask: 
true,
        autoShow : 
true,
        autoScroll: 
true,
        loadMask:
{msg:"数据加载中,请稍等"},
        bbar:
new Ext.PagingToolbar({
            pageSize:
20,
            store:storeMain,
            displayInfo:
true,
            displayMsg:
'当前显示 {0} - {1}条记录 /共 {2}条记录',
            emptyMsg:
"没有数据"
        }
)
    }
);
    storeMain.load(
{params:{start:0, limit:20,sort:'<%= SourceTable.PrimaryKey.MemberColumns[0].Name %>',dir:'desc'}});
}
);
<script runat="template">
// My functions here.
public string GetClassName(TableSchema table)
{
    
if(table==null)
    
{
        
return null;
    }

    
return table.Name + "Grid";
}

public string GetUrlName(TableSchema table)
{
    
if(table==null)
    
{
        
return null;
    }

    
return table.Name + "Grid"+".aspx";
}


script script
</script>
posted on 2009-02-18 13:36  一路前行  阅读(869)  评论(0编辑  收藏  举报