Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

ListGrid, DataSource and foreignKey

$
0
0
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

Viewing all articles
Browse latest Browse all 4756

Trending Articles