动态 store grid

private void AddField(Store store, RecordField field)
        {
            if (Ext.IsAjaxRequest)
                store.AddField(field);
            else
                store.Reader.Reader.Fields.Add(field);
        }
        public void LoadGrid(Store store, GridPanel grid, bool testData)
        {
            try
            {
                store.RemoveFields();

                //loop through each column to create the readerfields for the store
                foreach (FundScreenerReportColumn c in this.Columns)
                    this.AddField(store, new RecordField(c.ColumnName, RecordFieldType.Auto));

                //ADD GRID COLUMNS/FILTERS
                Column col = null;
                StringFilter sFilter = null;
                NumericFilter nFilter = null;
                ListFilter lFilter = null;

                this.Columns.Sort(new Comparison<FundScreenerReportColumn>(SortByOrder));
                grid.ColumnModel.Columns.Clear();
                grid.Plugins.Clear();
                //create Grid Filter
                GridFilters f = new GridFilters();
                grid.Plugins.Add(f);
                foreach (FundScreenerReportColumn c in this.Columns)
                {
                    col = new Column();
                    col.ColumnID = c.ColumnName;
                    col.Header = c.ColumnName;

                    col.Sortable = true;

                    if (c.DataType.Contains("date"))
                    {
                        col.Renderer.Fn = string.Format("Ext.util.Format.dateRenderer('{0}')", c.DisplayFormat);
                    }
                    if (c.DataType.Contains("float"))
                    {
                        col.Renderer.Fn = string.Format("Ext.util.Format.numberRenderer('{0}')", c.DisplayFormat);
                    }
                    if (c.ColumnName.ToLower().Contains("icon"))
                        col.Renderer.Fn = "getImage";

                    col.DataIndex = c.ColumnName;

                    grid.ColumnModel.Columns.Add(col);
            


                    //add appropriate filter
                    if (c.FilterGrid.Equals("Numeric"))
                    {
                        nFilter = new NumericFilter();
                        nFilter.DataIndex = c.ColumnName;
                        f.Filters.Add(nFilter);
                    }
                    else if (c.FilterGrid.Equals("List"))
                    {
                        lFilter = new ListFilter();
                        lFilter.DataIndex = c.ColumnName;
                        lFilter.Options = c.FilterGridValues.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        f.Filters.Add(lFilter);
                    }
                    else
                    {
                        sFilter = new StringFilter();
                        sFilter.SetActive(true);
                        sFilter.AutoDataBind = true;
                        sFilter.DataIndex = c.ColumnName;
                        f.Filters.Add(sFilter);
                    }
                 

                }

              
                grid.Reconfigure();
                // DataSet ds = rpt.GetData(false);

                store.DataSource = this.GetData(testData);
                store.DataBind();
                //this.GridPanel1.Title = rpt.ReportName;
                grid.DataBind();
                if (Ext.IsAjaxRequest)
                    grid.RefreshView();
            }
            catch (Exception er)
            {
                Utilities.NotificationError(er.ToString());
            }
        }

 

 

<ext:Store id="Store1" runat="server" autoload="false" AutoDataBind="false">
        <AjaxEventConfig IsUpload="true" />
        <Reader>
         <ext:JsonReader>
         </ext:JsonReader>
        </Reader>
    </ext:Store>


<ext:GridPanel id="GridPanel1" striperows="true" AutoDataBind="true" Title="No Report" header="false" trackmouseover="true" runat="server" storeid="Store1" autowidth="true" height="650">
        <SaveMask   ShowMask="true" />
        <LoadMask ShowMask="true" msg="Fetching" />
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
            </Columns>
        </ColumnModel>
        <View>
            <ext:GroupingView ID="GroupingView1" HideGroupedColumn="true" EmptyGroupText="No Groups" EnableGroupingMenu="true" runat="server" ForceFit="true" StartCollapsed="true" GroupTextTpl='<span id="ColorCode-{[values.rs[0].data.ColorCode]}"></span>{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})' EnableRowBody="true">
            </ext:GroupingView>
        </View>
        <Plugins>
           
        </Plugins>
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolBar1" runat="server" StoreID="Store1" PageSize="50" DisplayInfo="true" DisplayMsg="Displaying Results {0} - {1} of {2}">
                <Items>
                    <ext:ToolbarButton ID="btnToggleGroups" runat="server" Text="Expand/Collapse Groups" Icon="TableSort" Style="margin-left: 6px;" AutoPostBack="false">
                        <Listeners>
                            <Click Handler="#{GridPanel1}.getView().toggleAllGroups();" />
                        </Listeners>
                    </ext:ToolbarButton>
                </Items>
            </ext:PagingToolbar>
        </BottomBar>
        <Listeners>    
                <BeforeUpdate Handler="#{maskDiv}.removeClass('x-hide-display');" />
                <Update Handler="#{maskDiv}.addClass('x-hide-display');" />
        </Listeners>
    </ext:GridPanel>

你可能感兴趣的:(store)