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
Web Service (ASMX)
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<string, object> GetData(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression) { |
| Dictionary<string, object> data = new Dictionary<string, object>(); |
| 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; |
| } |
| } |