How to handle a master - detail situation with datasources?
Of course I can use two separate datasource to read the data from the server.
But how to update the data to the server in one transaction?
In that case you would want to have one POST request to the server per master record including it's details.
But I am not aware of the ability to setup such relation between datasources.
Ideally you want to have such JSON object:
{ Field1: xxx, Field2: yyy, Details: [{ DetField1: aa, DetField2: bb }, { DetField1: cc, DetField2: dd }] }
Any ideas?
Regards, Jaap
14 Answers, 1 is accepted
Unfortunately, Model relations are not currently supported. Therefore, a separate requests for master and child items will be required.
Regards,Rosen
the Telerik team
What whould happen if a datasource reads this result from the server:
{ Field1: xxx, Field2: yyy, Details: [{ DetField1: aa, DetField2: bb }, { DetField1: cc, DetField2: dd }] }
Whould the datasource accept this and in fact that a field will contain an array of objects?
Any idea if that will work. Of course I don't expect you support this in your widgets like the gird. But if the datasource accepts this, I can use that array as a local source for another datasource to display it in a grid and after manupilating the data save if back in the field of the original datasource and sync it to the server.
If you have no experience with this, I will try it myself.
Regards, Jaap
Indeed, the DataSource will load the records with such structure. However, the changes in the inner array will not be tracked, therefore when the parent items are submitted the changes of the inner array will not be present. Thus, you will need somehow to manually sync the parent and inner array when updated.
Regards,Rosen
the Telerik team
Use it to pass any extra detail lists
Because it's not part of the model, you might have to create a function that goes through the dirty data and grabs the items that need updating.
I also had to convert the given object to just a plain object
var oData = new Object();
for (ii in DETAIL)
oData(ii) = DETAIL(ii);
DETAIL = oData;
How can I make a simple invoice form for example ? A main part with customer informations and an editable grid with the detail.
If this simple problem has an acceptable solution, I choose Kendoui tomorow :)
Thanks.
The information in the header is not static. Imagine an Invoice. You enter informations in the main part (date, customer, etc.) AND you enter some lines in the detail.
And when you click Ok or Save, it should be done in a transaction. The serveur must receive all the information in a blick, the master and the detail.
But imagine now you modify this invoice and you delete a line in the detail grid, the detail line should not be deleted immediately in the database by the server but when the user click Ok, on an transaction... So, you cannot use the datasource as it should.
Of course, we can imagine a solution where a "change" event memorize the deleted or changed or added lines etc. But in this case, why should I use a framework where I have to code everything ?
For the kind of application I work for, in my opinion, it's the most important problem.
Hi,
have you got any workarounds for this issue??
Having in mind that this thread is quite old (6 years), I would like to ask you to elaborate a bit more on your current scenario and what your are trying to achieve.
Regards,
Nencho
Progress Telerik
How to handle a master - detail situation with datasources?
Of course I can use two separate datasource to read the data from the server.
But how to update the data to the server in one transaction?
In that case you would want to have one POST request to the server per master record including it's details.
Recently, one of your executive has replied me that I can use the Data function of the Read action to pass additional data.
I think I can pass the master details in an array using the above mentioned method. But how can i retrieve those values in controller?
Can you show me an example for the same?
The Data function can be used to send additional data to the server. However, sending complex objects and entire data sets is not recommended.
As my colleague has suggested in the support ticket you have submitted the recommended approach in hierarchical scenarios is to use a separate dataSource for the master and detail Grid. Furthermore, this makes more sense as usually the parent and child grid will show data from separate tables in the database that are related. In that scenario the Data() method can be used in the child grid to send the parent id to the read action.
Regards,
Viktor Tachev
Progress Telerik