Ext Net代码写在哪,会生效

2017-12-27  本文已影响0人  hi句身

前言

前台.

JavaScript 包括Ext语法.

///顶部Ext命名控件
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
/// body 或其他区域引入Ext, 这样就可以使用对象了. 注意如果 Namespace 不指定默认为 App. 此处指定为"", 这样, 所有的Ext对象用ID直接访问.
<body>
    <ext:ResourceManager runat="server" Namespace="" />
//1.1 界面加载后方法, 类似于$.ready(function(){})
    Ext.onReady(function () {
       
    })

后台. Ext.NET. C# 语法

<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!X.IsAjaxRequest)
        {
            LoadFunc(ViewBag.LoginUser.UserID, ..);
        }
    }

//2.3 DirectMethod 方法

 private void CreateGpl(System.Data.DataTable _rptData, GridPanel _gp, Store _store)
        {
            //清除旧数据与记录集
            _store.Reader.Clear();
            _gp.SelectionModel.Clear();
            _gp.ColumnModel.Columns.Clear();
            //_store.Model.Clear();
           
            if (_rptData.Rows.Count == 0)
            {
                X.Msg.Alert("提示", "无数据显示.").Show();
                _gp.Render();                
                return;
            }
            
            //1. 序号列
            _gp.ColumnModel.Columns.Add(new RowNumbererColumn
            {
                Text = "序号",
                Width = 45
            });
            
            List<ModelField> modelFields = new List<ModelField>();
            foreach (System.Data.DataColumn _dataColumn in _rptData.Columns)
            {
                var columnName = _dataColumn.ColumnName;

                        var _column = new  SummaryColumn();
                        _column.DataIndex = columnName;
                        _column.Text = columnNames[1];
                        _column.Align = Alignment.Right;                        
                        _column.SummaryType = SummaryType.Sum;
                        _column.Renderer = new Renderer("return Other.FormatMoney(value," + dataPres + ")");
                        _column.SummaryRenderer = new Renderer("return Other.FormatMoney(value," + dataPres + ")");
                        
                        _gp.ColumnModel.Columns.Add(_column);  
                    }
                }
                
                modelFields.Add(_modelField);
            }
            _store.Fields.AddRange(modelFields);
            _store.DataSource = _rptData.DefaultView;
            _store.DataBind();
            
            _store.LoadData(_rptData);
            // 重绘
            //SumStore.Reload();
            _gp.Render();
        }
 <ext:Button ID="QueryData" runat="server" Text="查询" Icon="Zoom">
                        <Listeners>
                            <Click Handler="Ext.net.Mask.show({ msg : '正在查询中...' });" />
                        </Listeners>
                    <DirectEvents>
                            <Click OnEvent="QueryData_Click" >
                                <ExtraParams>
                                    <ext:Parameter Name = "month" Value = "Ext.Date.format(dfmonth.getValue(), 'Ymd')"  Mode="Raw"/>
                                    <ext:Parameter Name = "keyWord" Value = "textName.getValue()"  Mode="Raw"/>
                                    <ext:Parameter Name = "orgId" Value = "ddfOrgName.getValue()"  Mode="Raw"/>
                                </ExtraParams>
                            </Click>
                        </DirectEvents>

对应后台代码:

/// <summary>
        ///  查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>        
        public void QueryData_Click(object sender, DirectEventArgs e)
        {
            QueryData.Disabled = true;
            try
            {
                var OrgID = e.ExtraParams["orgId"];
                var months = e.ExtraParams["month"];
                var keyWords = e.ExtraParams["keyWord"];

                BindData(OrgID, months, keyWords);
                QueryData.Disabled = false;                
            }
            catch (Exception ex)
            {
                QueryData.Disabled = false;                
                X.Msg.Alert("异常", ex.Message);
            }

            X.Mask.Hide();
        }

特别注意, 需要正常访问控件及使用, 需要修改页面的这个条件:

    <script type="text/javascript">
            Ext.net.ResourceMgr.isMVC = false;
    </script>

---------------------------------------分割线---------------------------------------------

进阶

DirectEvent和 DirectMethod

上一篇下一篇

猜你喜欢

热点阅读