ServerMapping with JsonReader and SqlDataSource

  1. #1

    ServerMapping with JsonReader and SqlDataSource

    Hi,

    I'm trying to figure out how to use ServerMapping. I have data received from SqlDataSource and can't figure out how to use ServerMapping.
    Could you please provide simple exmaple with SqlDataSource and GridPanel for me ? Please.



    Regards.
  2. #2
    For which reason do you need server mapping?
    Why don't you just use record fields with the named table fields?

    RecordField.Name = "ID";
    RecordField.Name = "OrderID";
    ...
  3. #3
    I wonder if I could use existing mappings on server in my backoffice application, I think this is what I could use ? Or maybe I misunderstand what the ServerMapping is for.
  4. #4
    I use ServerMapping for binding complex objects, which contain nested properties. "MyObject.Property1.Property2.Text" would be a ServerMapping for the object "MyObject".

    I don't know if ServerMapping is just there to use it for this scenario or if there are other situations to use it.
  5. #5
    Hi,

    The ServerMapping serves for both scenarios, a simple mapping or mapping complex.

    Here are two examples:

    Simple:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select id, nome from usuario" />
    
    <ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1" OnRefreshData="Store1_Refresh">
        <Reader>
            <ext:JsonReader IDProperty="id">
                <Fields>
                    <ext:RecordField Name="id" ServerMapping="id" Type="Int" />
                    <ext:RecordField Name="nome" ServerMapping="nome" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    Complex:

    create table usuario (
        id int identity(1, 1) not null,
        nome varchar(30) not null,
        id_perfil int not null,
        primary key (id)
    );
    
    create table perfil (
        id int identity(1, 1) not null,
        nome varchar(30) not null,
        primary key (id)
    );
    
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" TableName="usuarios" Select="new (id, nome, perfil)" />
    
    <ext:Store ID="Store1" runat="server" DataSourceID="LinqDataSource1" OnRefreshData="Store1_Refresh">
        <Reader>
            <ext:JsonReader IDProperty="id">
                <Fields>
                    <ext:RecordField Name="id" ServerMapping="id" Type="Int" />
                    <ext:RecordField Name="nome" ServerMapping="nome" />
                    <ext:RecordField Name="perfil" ServerMapping="perfil.nome" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    With ServerMapping I map my object / attribute with the name and I say as it is called.

    This makes it easy. ;)

    []'s
    Vinicius
  6. #6
    Yes, but for
    <ext:RecordField Name="id" ServerMapping="id" Type="Int" />
    <ext:RecordField Name="nome" ServerMapping="nome" />
    you don't need to specify ServerMapping. You can leave that blank.
  7. #7
    Quote Originally Posted by nextSTEP View Post
    Yes, but for
    <ext:RecordField Name="id" ServerMapping="id" Type="Int" />
    <ext:RecordField Name="nome" ServerMapping="nome" />
    you don't need to specify ServerMapping. You can leave that blank.
    Yeah nextSTEP, actually there is no need to use ServerMapping this case.

    I used only for example, assuming that use or not use ServerMapping this scenario the result is the same.

    But by maintaining and leave the clean code, it is good that is not used ServerMapping but only the Name.

    []'s
    Vinicius

Similar Threads

  1. JSONReader problem
    By atze187 in forum 1.x Help
    Replies: 9
    Last Post: Nov 11, 2011, 1:57 PM
  2. ServerMapping with more attribute
    By Maia in forum 1.x Help
    Replies: 3
    Last Post: Aug 12, 2010, 4:48 PM
  3. Problem using ext:JsonReader
    By egodoy in forum 1.x Help
    Replies: 1
    Last Post: Dec 03, 2008, 3:46 PM

Tags for this Thread

Posting Permissions