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

[Solved] Reorder Columns Not Working

1 Answer 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 27 May 2009, 01:34 PM
I'm using version 2009.1.311.35 of the RadGrid control. I have the grid configured to obtain the datasource from a web service and reorder columns on the client. Upon reordering the columns, the column header and data are reordered. When I go to another page of data, however, the header remains reordered, but the data does not. The data goes back to the original ordering. Is this a bug or somethig to do with my configuration?

Below is a simple example. After reordering, the sample will display the UniqueName and DataField for each column. It appears that the client-side JS code is not properly setting the DataField after reordering.

ASPX
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
 
    <script type="text/javascript"
        function ColumnSwapped(sender, eventArgs) { 
            var cols = $find(RadGrid1_ClientId).get_masterTableView()._columnsInternal; 
            for (var idx = 0; idx < cols.length; idx++) { 
                alert("Column:" + idx + ", UniqueName:" + cols[idx]._data.UniqueName + ", DataField:" + cols[idx]._data.DataField); 
            } 
        } 
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
        <asp:ScriptManager ID="ScriptManager" runat="server" AsyncPostBackTimeout="1000" 
            ScriptMode="Release"
        </asp:ScriptManager> 
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" 
            AllowMultiColumnSorting="False" AutoGenerateColumns="False" Width="100%" AllowMultiRowSelection="True" 
            Height="565px" PageSize="20" ShowStatusBar="True" BorderWidth="1px" GridLines="Vertical"
            <MasterTableView> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="NUMBERS" HeaderText="NUMBERS" UniqueName="NUMBERS"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="LETTERS" HeaderText="LETTERS" UniqueName="LETTERS"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="WORDS" HeaderText="WORDS" UniqueName="WORDS"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings AllowColumnsReorder="true" ColumnsReorderMethod="Reorder" ReorderColumnsOnClient="true"
                <ClientEvents OnColumnSwapped="ColumnSwapped" /> 
                <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                <Resizing AllowColumnResize="true" /> 
                <Selecting AllowRowSelect="true" /> 
                <DataBinding Location="~/TestService.asmx" SelectMethod="GetData"
                </DataBinding> 
            </ClientSettings> 
        </telerik:RadGrid> 
    </div> 
    </form> 
 
    <script type="text/javascript"
        var RadGrid1_ClientId = "<%= RadGrid1.ClientID %>"
    </script> 
 
</body> 
</html> 
 


Web Service (ASMX)
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [ScriptService] 
    [System.ComponentModel.ToolboxItem(false)] 
    public class TestService : System.Web.Services.WebService { 
 
        [WebMethod(EnableSession = true)] 
        public Dictionary<stringobject> GetData(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression) { 
            Dictionary<stringobject> data = new Dictionary<stringobject>(); 
            List<object> rows = new List<object>(); 
 
            for (int i = 0; i < 100; i++) { 
                rows.Add(new { 
                    NUMBERS = 1, 
                    LETTERS = "A"
                    WORDS = "One" 
                }); 
                rows.Add(new { 
                    NUMBERS = 2, 
                    LETTERS = "B"
                    WORDS = "Two" 
                }); 
                rows.Add(new { 
                    NUMBERS = 3, 
                    LETTERS = "C"
                    WORDS = "Three" 
                }); 
                rows.Add(new { 
                    NUMBERS = 4, 
                    LETTERS = "D"
                    WORDS = "Four" 
                }); 
                rows.Add(new { 
                    NUMBERS = 5, 
                    LETTERS = "E"
                    WORDS = "Five" 
                }); 
                rows.Add(new { 
                    NUMBERS = 6, 
                    LETTERS = "F"
                    WORDS = "Six" 
                }); 
            } 
 
            data.Add("Count", rows.Count); 
 
            int numElements = maximumRows; 
            if (maximumRows > (rows.Count - startRowIndex)) { 
                maximumRows = rows.Count - startRowIndex; 
            } 
 
            var tmpData = rows.GetRange(startRowIndex, maximumRows); 
 
            data.Add("Data", tmpData); 
 
            return data; 
        } 
    } 

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavel
Telerik team
answered on 28 May 2009, 06:56 AM
Hello Jeff,

I was able to observe the problem using the code/markup you provided. However this issue seems to be fixed in the latest official release of our controls so I will ask you to upgrade to it in order to resolve it. You can read this knowledge base article for a step-by-step explanation on how to upgrade.

Kind regards,
Pavel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Share this question
or