Beispiel #1
0
        public void BindStore(Store store)
        {
            store.ID = string.Format("store{0}", this.ID);

            if (store.Reader.Count == 0)
            {
                var valueField = ValueField.ToLower() == "value" ? "Value" : ValueField;

                store.Reader.Add(new Ext.Net.JsonReader
                                {
                                    IDProperty = valueField,
                                    Root = "data",
                                    TotalProperty = "total"
                                }
                            );

                store.AddField(new Ext.Net.RecordField { Name = valueField });
                store.AddField(new Ext.Net.RecordField { Name = DisplayField.ToLower() == "text" ? "Text" : DisplayField });
            }

            store.BaseParams.Add(new Ext.Net.Parameter {
                    Name = "DisplayField",
                    Value = this.DisplayField,
                    Mode = Ext.Net.ParameterMode.Value
                });

            store.BaseParams.Add(new Ext.Net.Parameter {
                    Name = "filter",
                    Value = "#{" + ID + "}.getText()",
                    Mode = Ext.Net.ParameterMode.Raw
                });
        }
Beispiel #2
0
        public void BindStore(Store store)
        {
            store.AutoLoad = !LoadOnActive && AutoLoadStore;
            store.ID = string.Format("store{0}", this.ID);
            store.RemoteSort = true;
            store.UseIdConfirmation = true;

            if (store.Reader.Count == 0)
            {
                store.Reader.Add(new Ext.Net.JsonReader {
                    IDProperty = this.IDProperty,
                    Root = "data",
                    TotalProperty = "total"
                });

                foreach (Ext.Net.ColumnBase column in ColumnModel.Columns)
                    store.AddField(new Ext.Net.RecordField { Name = column.DataIndex, Type = UIHelper.GetFieldType(column) });
            }

            if (!this.DisableBottomBar) {
                if (!store.BaseParams.Any(p => p.Name.ToLower() == "start")) store.BaseParams.Add(new Ext.Net.Parameter { Name = "start", Value = "0", Mode = Ext.Net.ParameterMode.Raw });
                if (!store.BaseParams.Any(p => p.Name.ToLower() == "limit")) store.BaseParams.Add(new Ext.Net.Parameter { Name = "limit", Value = this.PageSize.ToString(), Mode = Ext.Net.ParameterMode.Raw });
            }

            var dirParam = store.BaseParams.Where(p => p.Name.ToLower() == "dir").FirstOrDefault();
            if (dirParam == null) store.BaseParams.Add(new Ext.Net.Parameter { Name = "dir", Value = "DESC" });

            var sortParam = store.BaseParams.Where(p => p.Name.ToLower() == "sort").FirstOrDefault();
            if (sortParam == null) store.BaseParams.Add(new Ext.Net.Parameter { Name = "sort", Value = this.IDProperty });

            store.SortInfo.Field = sortParam == null ? this.IDProperty : sortParam.Value;
            store.SortInfo.Direction = dirParam == null || dirParam.Value.ToLower() == "desc" ? Ext.Net.SortDirection.DESC : Ext.Net.SortDirection.ASC;

            if (FilterParams != null && FilterParams.Count > 0)
            {
                StringBuilder param = new StringBuilder();

                bool isValueMode = false, isFirst = true;
                foreach (var prm in FilterParams)
                {
                    isValueMode = prm.Mode == Ext.Net.ParameterMode.Value;
                    if (!isFirst) param.Append(",");
                    param.Append(AddFilterItem(string.Empty, prm.Name, "And", "Equals", prm.Value, string.Empty, isValueMode));
                    if (isFirst) isFirst = false;
                }

                store.BaseParams.Add(new Ext.Net.Parameter { Name = "FilterBase", Value = string.Format("'{0}'", param.ToString()), Mode = Ext.Net.ParameterMode.Raw });
            }

            if (this.EnableSearch)
                store.BaseParams.Add(new Ext.Net.Parameter { Name = "Filter", Value = string.Format("#{{hidden_SearchCondition_{0}}}.value", this.ID), Mode = Ext.Net.ParameterMode.Raw });

            if (FirstRowSelectOnLoad)
                store.Listeners.Load.Handler = "if (!#{" + (this.ID ?? string.Empty) + "}.hasSelection()) { #{" + (this.ID ?? string.Empty) + "}.getSelectionModel().selectFirstRow(); } #{" + (this.ID ?? string.Empty) + "}.view.focusRow(0);" + store.Listeners.Load.Handler;

            if (LoadOnActive)
                store.Listeners.Load.Handler += "this.loaded = true;";
        }