Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid, DataSource and foreignKey

    Hi,

    I have two datasources described like this
    Code:
    isc.RestDataSource.create({
        ID:"client",
        fields: [
            {name:"id", type:"sequence", title:"id", primaryKey:true},
            {name:"name", type:"text", title:"Nom", required:true}
        ],
        dataFormat:"json", DSDataFormat:"json",
        sendMetaData: true,
        dataURL:"/rapi/clients/"
    });
    
    isc.RestDataSource.create({
        ID: "cc_clientlogs_ds",
        dataURL: "/rapi/clientlogs/",
        dataFormat:"json", DSDataFormat:"json",
        sendMetaData: false,
        fields: [
            {name:"id", type:"integer", title:"id", primaryKey:true, autoGenerated:true},
            {name:"client", type:"integer", title:"Client", foreignKey:"client.id", foreignDisplayField:"name"},
            {name:"entry_date", type: "datetime"},
            {name:"comment", type: "text"},
            {name:"source", type:"text"}
        ]
    });
    JSON Response from server for "client" restdatastore:
    Code:
    {"response": {"startRow": 0, "data": [{"id": 1, "name": "AAA"}, {"id": 2, "name": "BBB"}, {"id": 3, "name": "CCC"}, {"id": 4, "name": "DDD"}, {"id": 5, "name": "EEE"}], "totalRows": 5, "success": true, "endRow": 4}}
    JSON Response from server fro "cc_clientlogs_ds" restdatastore:
    Code:
    {"response": 
      {"data": [
        {"id": 9, "client": 1, "entry_date": "2014-11-01T11:54:36.506Z", "comment": "Clossseeeeeee-uh !!!!", "source": "M"},
        {"id": 8, "client": 1, "entry_date": "2014-11-01T11:48:14.715Z", "comment": "Opeeeeeeeeeennnnnnnnnnnnn", "source": "M"},
        {"id": 7, "client": 1, "entry_date": "2014-11-01T11:47:06.423Z", "comment": "Test-euh", "source": "M"},
        {"id": 6, "client": 1, "entry_date": "2014-11-01T11:45:36.572Z", "comment": "Ceci est une autorisation d'acc\u00e8s sur \nplusieurs lignes\n\nEt paf !!", "source": "M"},
        {"id": 5, "client": 1, "entry_date": "2014-11-01T11:39:24.353Z", "comment": "Test de de fermeture", "source": "M"},
        {"id": 4, "client": 1, "entry_date": "2014-10-31T22:12:31.662Z", "comment": "ouverture", "source": "M"},
        {"id": 3, "client": 2, "entry_date": "2014-10-31T20:45:24.061Z", "comment": "Ceci est un test", "source": "M"},
        {"id": 2, "client": 1, "entry_date": "2014-10-31T18:59:04.754Z", "comment": "Et paf un test de fermeture", "source": "M"},
        {"id": 1, "client": 1, "entry_date": "2014-10-31T18:52:36.284Z", "comment": "Plopi plopa", "source": "S"}
      ], 
      "success": true}
    }

    creation of the grid:
    Code:
    isc.ListGrid.create({
        ID: "cc_clientstatus_clientlogs_lg",
        autoDraw: false,
        dataSource: "cc_clientlogs_ds",
        autoFetchData:true,
        useAllDataSourceFields:true,
        fields:[{name:"id", hidden:true }]
    });

    What I want is to display the client.name in a listgrid that is bound to cc_clientlogs_ds instead of the id provided by cc_clientlogs_ds.client . I am on it since some hours now and can't find solutions in doc or forum...
    I waq thinking that foreignKey and foreignDisplayField would suffice but apprently no.

    Thanks for your help !

    SmartClient Version: v10.0p_2014-10-10/EVAL Development Only

    #2
    See DataSourceField.includeFrom - since you are not using our server framework, you can't use this feature directly, but it describes the settings you should use and the data to return from your REST services.

    Comment


      #3
      So I added to my cc_clientlogs_ds RestDataSource a field "clientname" and made a little modification to the "client" field

      Code:
      {name:"client", type:"integer", title:"Client", foreignKey:"client.id" },
      {name:"clientname", includeFrom:"client.name" },
      Still no success. I tried to add "hidden:true" to "clientname" and "displayField:"clientname"" to "client" field, no success...

      The "client" datasource is fetched (see in SmartClient Developer Console).

      and the data to return from your REST services.
      I don't see anything about that in doc for DataSourceField.includeFrom.
      should the json response be modified ?

      Thanks for your help !

      Comment


        #4
        Like we said, you can't use the includeFrom feature. The docs explain what data needs to be returned. Read both what we said and the docs more closely.

        Comment


          #5
          Sorry, I understood that I have to use includeFrom because I was not using the smartclient server.

          But now what I understand is that I can't use datasource relation on the client-side at all...

          I think I will go with DatSourceField.valueXPath and nest the "client" properties in the returned json response from the server for "cc_clientlogs_ds".

          Comment


            #6
            That's not what the docs we referred you to suggest, it suggests using displayField. You're definitely having trouble reading the things we're telling you in both the forums and the docs, and we'd suggest just reading more slowly and carefully.

            Comment


              #7
              So you are suggesting me to add a "clientname" hidden field to my RestDataSource "cc_clientlogs_ds" (and return the correct value in the server response), and add displayField="clientname" to the "client" field ?

              Comment

              Working...
              X