[CLOSED] ServerMapping and RemoteSort

  1. #1

    [CLOSED] ServerMapping and RemoteSort

    Hello,

    I was wondering if it was possible to adjust the Store to send the ServerMapping when RemoteSort is enabled? If this is not possible, and I can imagine there are some scenarios where you would want to pass back the Name instead of the ServerMapping ... would it be possible to add a SortName ?

    Thanks for the help both of you.

    Cheers,
    Timothy
  2. #2

    RE: [CLOSED] ServerMapping and RemoteSort

    Hi,

    ServerMapping property is not serialized therefore is not accessable on client side. The store can you use only existing field's names therefore additinal names can't be used (also if we will use custom names the grid can't determine on what field was performed the sort operation)


    It can be implemented but it is required big changes in store/grid/gridview js classes
  3. #3

    RE: [CLOSED] ServerMapping and RemoteSort

    OK, with the below example is there anyway I can return "Department.Name" to the Store1_RefreshData function instead of "Department" ?

    I don't want to start getting into case statements to swap out real meaning on the server-side.

    Example:

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
            protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
            {
                Store1.DataSource = Employee.GetAll();
                Store1.DataBind();
    
                Label1.Text = "Sort Column = " + e.Sort;
            }
        
            public class Employee
            {
                public int ID { get; set; }
                public string Name { get; set; }
                public string Surname { get; set; }
                public Department Department { get; set; }
    
                public static List<Employee> GetAll()
                {
                    return new List<Employee>
                               {
                                   new Employee
                                       {
                                           ID = 1,
                                           Name = "Nancy",
                                           Surname = "Davolio",
                                           Department = Department.GetAll()[0]
                                       },
                                   new Employee
                                       {
                                           ID = 2,
                                           Name = "Andrew",
                                           Surname = "Fuller",
                                           Department = Department.GetAll()[2]
                                       }
                               };
                }
            }
    
            public class Department
            {
                public int ID { get; set; }
                public string Name { get; set; }
    
                public static List<Department> GetAll()
                {
                    return new List<Department>
                               {
                                   new Department {ID = 1, Name = "Department A"},
                                   new Department {ID = 2, Name = "Department B"},
                                   new Department {ID = 3, Name = "Department C"}
                               };
                }
            }
    
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Coolite Toolkit Example - Server Mapping</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData" RemoteSort="true">
                <Proxy>
                    <ext:DataSourceProxy />
                </Proxy>
                <Reader>
                    <ext:JsonReader ReaderID="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Surname" />
                            <ext:RecordField Name="Department" ServerMapping="Department.Name" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel ID="GridPanel1" EnableViewState="true" AutoHeight="true" runat="server"
                StoreID="Store1" Title="List" Icon="Application">
                <ColumnModel ID="ColumnModel1" runat="server">                
                    <Columns>
                        <ext:Column Header="ID" Sortable="true" DataIndex="ID" />
                        <ext:Column Header="NAME" Sortable="true" DataIndex="Name" />
                        <ext:Column Header="SURNAME" Sortable="true" DataIndex="Surname" />
                        <ext:Column DataIndex="Department" Header="Department" Width="240"/>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask Msg="Loading" ShowMask="true" />
            </ext:GridPanel>
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Cheers,
    Timothy
  4. #4

    RE: [CLOSED] ServerMapping and RemoteSort

    Hi,

    You can write function which can juxtapose Name <-> ServerMapping


    public string GetSortName(string name)
    {
      foreach (RecordField field in strStore.Reader.Reader.Fields)
      {
        if(field.Name == name)
        {
               return string.IsNullOrEmpty(field.ServerMapping) ? field.Name : field.ServerMapping;
        }
      }
      return name;
    }
    Then just use that function in Store1_RefreshData


    string sortName = this.GetSortName(e.Sort);
  5. #5

    RE: [CLOSED] ServerMapping and RemoteSort

    Thanks, I will use the example you provided. I'm wondering tho, to make it more intuitive for other users would it be possible to attach the RecordField in the StoreRefreshDataEventArgs for ease of use?

    Sorry for being a pest :)

    Cheers,
    Timothy
  6. #6

    RE: [CLOSED] ServerMapping and RemoteSort



    I implented this in version .8 and it worked perfectly. Now that i'm refactoring to 1.0, this no longer works. If i set the ServerMapping property it will throw an error:


    <H2>Object reference not set to an instance of an object. </H2>


    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:


    <TABLE width="100%" bgColor=#ffffcc>
    <TBODY>
    <TR>
    <TD><CODE>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</CODE> </TD></TR></TBODY></TABLE>
    Stack Trace:


    <TABLE width="100%" bgColor=#ffffcc>
    <TBODY>
    <TR>
    <TD><CODE>[NullReferenceException: Object reference not set to an instance of an object.]
    Ext.Net.StoreDataBound.GetFieldValue(AutoGenerated FieldProperties property, Object obj, RecordField field) +307
    Ext.Net.StoreDataBound.BindRecord(AutoGeneratedFie ldProperties[] autoFieldProperties, StringBuilder sb, Object obj) +474
    Ext.Net.StoreDataBound.PerformDataBinding(IEnumera ble data) +271
    Ext.Net.StoreDataBound.OnSelect(IEnumerable data) +40
    System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +31
    Ext.Net.StoreDataBound.PerformSelect() +181
    Ext.Net.StoreDataBound.DataBind() +327
    Ext.Net.Store.RaiseAjaxPostBackEvent(String eventArgument) +1917
    Ext.Net.Store.System.Web.UI.IPostBackEventHandler. RaisePostBackEvent(String eventArgument) +107
    Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument) +2734
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +175
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
    </PRE></CODE></TD></TR></TBODY></TABLE>
  7. #7

    RE: [CLOSED] ServerMapping and RemoteSort

    Hi,

    Please create separate topic with test sample which demonstrates the problem. Just this topic is solved already

Similar Threads

  1. [CLOSED] RemoteSort for buffered store
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 46
    Last Post: May 27, 2012, 8:02 PM
  2. [CLOSED] RemoteSort method
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 19
    Last Post: Apr 20, 2012, 8:43 PM
  3. Replies: 0
    Last Post: Oct 08, 2011, 8:02 PM
  4. [CLOSED] GridPanel RemoteSort
    By Marcelo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 28, 2011, 8:12 PM
  5. [CLOSED] [1.0] RemoteSort with IsComplex field
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 27, 2010, 4:07 PM

Posting Permissions