日期:2014-05-16  浏览次数:20405 次

extjs中的grid不显示问题
JScript code
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.state.*'
]);
Ext.define('Company', {
    extend: 'Ext.data.Model',
    fields: [
       { name: 'name', type: 'string' },
       { name: 'tel', type: 'string' },
       { name: 'mail', type: 'string' },
       { name: 'qq', type: 'string' },
       { name: 'datetime', type: 'date' }
    ]
   
});

Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
    function change(val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '</span>';
        } else if (val < 0) {
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    }

    /**
    * Custom function used for column renderer
    * @param {Object} val
    */
    function pctChange(val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '%</span>';
        } else if (val < 0) {
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }
   
    var store = Ext.create('Ext.data.Store', {
     
        model: 'Company',
        proxy: {
            //异步获取数据,这里的URL可以改为任何动态页面,只要返回JSON数据即可   
            type: 'ajax',
            url: 'extzz.aspx?userslist=list',
            reader: {
                type: 'json',
                root: 'data'             

            }
        },

        autoLoad: true
    });

    store.on('load', function (tempstore) {

        alert(tempstore.getCount())
     
      });

   

    // create the Grid
    var grid = Ext.create('Ext.grid.Panel', {
        store: store,
        //stateful: true,
        collapsible: true,
        multiSelect: true,
        //stateId: 'stateGrid',
        columns: [
            {
                text: '用户名',
                flex: 1,
                autoHeight: true,
                sortable: true,
                dataIndex: 'name'
            },
            {
                text: '电话',
                width: 75,
                autoHeight: true,

                sortable: true,
                //renderer: 'usMoney',
                dataIndex: 'tel'
            },
            {
                text: '邮箱',
                autoHeight: true,

                width: 75,
                sortable: true,
                //renderer: change,
                dataIndex: 'mail'
            },
            {
                text: 'qq',
                autoHeight: true,

                width: 75,
                sortable: true,
                //renderer: pctChange,
                dataIndex: 'qq'
            },
            {
                text: '添加时间',
                autoHeight: true,

                width: 85,
                sortable: true,
                renderer: Ext.util.Format.dateRenderer('m/d/Y'),
                dataIndex: 'datetime'
            }

        ],
        height: 350,
        width: 600,
        title: '用户信息列表',
        renderTo: 'extjslianxi',
        viewConfig: {
            stripeRows: true,
            enableTextSelection: true
        }
    });
   
});




C# code
StringBuilder sb = new StringBuilder();
        string sql = "select * from users";
        DataTable dt = DbHelperSQL.Query(sql).Tables[0];
        sb.Append("{data:[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("{\"name\":\"" + dt.Rows[i]["name"].ToString() + "\",\"tel\":\"" + dt.Rows[i]["tel"].ToSt