This is a migrated thread and some comments may be shown as answers.

DynamicRadGrid ForeignKey Column Ordering in a DynamicData application

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wade
Top achievements
Rank 1
Wade asked on 25 Jan 2013, 06:11 PM
After doing about a day of searching around the web, these forums, and co-workers that have done similar applications as the one I'm currently tasked with, I'm forced to start a thread for help.

My issue: I'm using the Telerik DynamicRadGrid control in a DynamicData 4.0 web application and am able to use [Display(Order=-1)] in order to position my ForeignKey columns for a specific table at in a specific order in the INSERT and EDIT templates, but the ordering is not reflected in the DynamicRadGrid column ordering. I need to move a column from the far right (end) of the column listing in my DynamicRadGrid to the far left (start) of the column listing in my DynamicRadGrid control.

The DynamicRadGrid control in my DynamicData PageTemplate ListDetails.aspx file:
<dynamic:DynamicRadGrid ID="RadGrid1" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false"
                PageSize="15" PagerStyle-Mode="NextPrevAndNumeric" runat="server" DataSourceID="GridDataSource"
                AllowAutomaticUpdates="true" AllowAutomaticInserts="true" OnItemCommand="RadGrid1_ItemCommand"
                OnItemDataBound="RadGrid1_ItemDataBound " AllowAutomaticDeletes="true" OnPageIndexChanged="RadGrid1_PageIndexChanged"
                OnDataBound="RadGrid1_DataBound">
                <ExportSettings ExportOnlyData="true" IgnorePaging="true" Excel-Format="ExcelML"
                    OpenInNewWindow="true">
                </ExportSettings>
                <MasterTableView CommandItemDisplay="Top" UseAllDataFields="true">
                    <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToExcelButton="true" />
                </MasterTableView>
                <ClientSettings EnablePostBackOnRowClick="true">
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
            </dynamic:DynamicRadGrid>
            <asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" EnableUpdate="true" />
            <asp:QueryExtender ID="GridQueryExtender" TargetControlID="GridDataSource" runat="server">
                <asp:DynamicFilterExpression ControlID="FilterRepeater" />
            </asp:QueryExtender>


The control is populated via the Page_Init() in the code behind:
protected void Page_Init(object sender, EventArgs e)
 {
     table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
     RadGrid1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
     FormView1.SetMetaTable(table);
     GridDataSource.EntityTypeFilter = table.EntityType.Name;
     DetailsDataSource.EntityTypeFilter = table.EntityType.Name;
 }

The [Display(Order=-1)] code is found in my PartialModelClasses Class and actually works when viewing/editing a specific record on an individual basis and not in the DynamicRadGrid control, which leads me to believe that the issue lies in support of the feature in the Telerik control and not in my code.

Any thoughts, ideas, or input would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Wade
Top achievements
Rank 1
answered on 25 Jan 2013, 08:11 PM
Resolved.

Hopefully this helps someone in the future:

protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
 
            AllowAutomaticUpdates = true;
            AllowAutomaticDeletes = true;
 
            MetaTable metaTable = this.FindMetaTable();
 
            List<string> list = new List<string>();
            foreach (MetaColumn column in metaTable.PrimaryKeyColumns)
            {
                list.Add(column.Name);
            }
            MasterTableView.DataKeyNames = list.ToArray();
 
            foreach (MetaColumn column in metaTable.Columns)
            {
                if (!column.Scaffold || column.IsLongString || column is MetaChildrenColumn)
                {
                    continue;
                }
 
                DynamicGridBoundColumn gridColumn = new DynamicGridBoundColumn();
 
                var c = column.Attributes;
 
                foreach (Attribute a in c)
                {
                    if (a.TypeId.ToString().Contains("DisplayAttribute"))
                    {
                        var colAtt = (System.ComponentModel.DataAnnotations.DisplayAttribute)(a);
                        gridColumn.OrderIndex = colAtt.Order;
                    }
                }
 
                gridColumn.DataField = column.Name;
                gridColumn.ConvertEmptyStringToNull = column.ConvertEmptyStringToNull;
                gridColumn.DataFormatString = column.DataFormatString;
                gridColumn.UIHint = column.UIHint;
                gridColumn.HtmlEncode = column.HtmlEncode;
                gridColumn.NullDisplayText = column.NullDisplayText;
                gridColumn.ApplyFormatInEditMode = column.ApplyFormatInEditMode;
                gridColumn.HeaderText = column.DisplayName;
 
                if (column.ColumnType == typeof(bool))
                {
                    gridColumn.DefaultInsertValue = "false";
                }
                if (column.ColumnType == typeof(Decimal))
                {
                    gridColumn.DefaultInsertValue = "1.0";
                }
 
                MasterTableView.Columns.Add(gridColumn);
            }
        }
Tags
Grid
Asked by
Wade
Top achievements
Rank 1
Answers by
Wade
Top achievements
Rank 1
Share this question
or