This is a migrated thread and some comments may be shown as answers.

Apply Edit Template after adding new data

6 Answers 73 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 23 Dec 2011, 07:48 PM
I have a raddataform with two templates:

Edit Template
AddNew Template

The DomainDataSource is bound to a collection of Customers

I load the dataform and using "Editor.AddNewItem()", the editor will show the AddNew template... fine

I have added a "Save" button to the dataform by overriding the base controltemplate. When the user clicks the "Save" button, an MVVM command will call SubmitChanges on the DomainDataSource.

I have hooked up the ChangesSubmitted event of domaindatasource... it will now load the customer that was just added:
QueryParameter qp = new QueryParameter();
qp.Value = (e.ChangeSet.AddedEntities[0] as Customer).OrganizationUserId;
qp.ParameterName = "organizationUserId";
organizationUserDomainDataSource.QueryParameters[0] = qp;
organizationUserDomainDataSource.Load();

This works fine... the dataform will show the added record, but the editor continues to use the AddNew template... how can i switch to the edit template?

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 Dec 2011, 09:09 AM
Hi Peter,

Could you try to invoke CommitEdit command of RadDataForm as well? Do you get the same behavior ? 

 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
HDC
Top achievements
Rank 1
answered on 28 Dec 2011, 10:04 AM
Hi Maya,

Does not change anything, the AddNew template remains the active template

Best Regards,

Peter
0
Maya
Telerik team
answered on 28 Dec 2011, 02:15 PM
Hi,

I have tried to reproduce the issue you reported, but still without any success. Could you share a bit more information about your exact scenario ? Generally, any relevant information and code-snippet would be helpful so that I could simulate your scenario.

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
HDC
Top achievements
Rank 1
answered on 28 Dec 2011, 04:06 PM
Hi Maya,

I would be very interested in seeing that sample wherein this works if you have one.

The scenario i'm using is quite complicated and it has a lot of code. It also uses MVVM.

I did the following:

I have create a custom dataform component "ExqiDataForm" that inherits from RadDataForm. The reason why i did that is so that i could override the control template for all of the RadDataForms of that type. In the control template i added a third button "Save".

I have created a RadWindow for editing the details of an Entity called "OrganizationUser". On that window i have placed a ExqiDataForm with two templates... one for Adding and one for Editing an OrganizationUser. The dataform is bound to a DomainDataSource.

When the user clicks on the Add button in the main application, it will instantiate the RadWindow containing the ExqiDataForm and it will execute following code on the ExqiDataForm:
OrganizationUsersEditor.AddNewItem(); 

This will effectievely make the OrganizationUserEditor display the AddNew template.

When the user clicks on the SAVE button on the ExqiDataForm, it will execute an MVVM command that will execute a SubmitChanges() on the RadDomainDataSource. I have also hooked the SubmittedChanges event on the DomainDataSource bound to the dataform. So when SubmitChanges is executed in MVVM, the SubmittedChanges event is fired right after. In this event, i reload the DomainDataSource like this:
QueryParameter qp = new QueryParameter();
qp.Value = (e.ChangeSet.AddedEntities[0] as OrganizationUser).OrganizationUserId;
qp.ParameterName = "organizationUserId";
organizationUserDomainDataSource.QueryParameters[0] = qp;
organizationUserDomainDataSource.Load();

This is necessary, otherwise the DomainDataSource will not contain the database record that we will edit straight after. It is here that it goes wrong... i would expect the DataForm to be in edit mode right after this load() command, but it is not.

What am i doing wrong?

Best Regards,

Peter


0
Accepted
Maya
Telerik team
answered on 03 Jan 2012, 09:36 AM
Hello Peter,

I am attaching the sample project I used for the test. As I am not aware of your custom command, I just handled Click event of the Save button and called the CommitEdit() and SubmitChanges() methods. Still. once the Save button is pressed, the new item is saved and the template for a new item is change with a one for read-only mode.  
Could you take a look at the application and let me know whether you can get the same behavior on it as the one in your project ? Is there anything that I am missing ?

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
HDC
Top achievements
Rank 1
answered on 04 Jan 2012, 05:16 PM
Hi Maya,

Thanks for putting up the effort for creating a demo app.

My situation is quite different because i'm using DataTemplates to edit the data.

Because the command executed by the save button is in a viewmodel, it's not so easy to execute CommitEdit on the dataform object.

So I have leaked the DataForm to the viewmodel and executed the "CommitEdit" on it in the viewmodel. This has done the trick and the dataform now switches from AddNew template to the Edit template without problems.

It's not particularly "clean", but i don't see any other option right now and it does solve my problem.

Thanks a lot for you help!

Peter
Tags
DataForm
Asked by
HDC
Top achievements
Rank 1
Answers by
Maya
Telerik team
HDC
Top achievements
Rank 1
Share this question
or