Popup editor in Edit mode vs Add mode

1 Answer 376 Views
DropDownList Grid Window
serge
Top achievements
Rank 2
Bronze
Iron
Iron
serge asked on 17 May 2021, 05:38 PM | edited on 17 May 2021, 06:03 PM

In a kendo grid with popup edition, I have the EditTemplate for my DTO object.

When I click on "+Add" grid button I will have the popup with the title "Edit" and if I click on "/Edit", I will have the same popup, with same title. 

1) Is there a way to change the popup title in "Add" when I add the object, and "Edit" if I edit it?

2) More than that, I need to "readonly" the DropDown in "edit" mode, and enable it in "add" mode. How to achieve it?

Knowing that the Model in the EditorTemplate is always null, there is any way to do verifications on the server Model...

 

3) When I add new object, I have a logic to prepare the DTO, before displaying it to the user. However, I have only the method that


[AcceptVerbs("Post")]
public ActionResult ByOneCreate([DataSourceRequest] DataSourceRequest request, MyDTO dto)

is there a way to use a method like this, to pre-fill the initially created object:

[AcceptVerbs("Get")]
public ActionResult ByOneCreate([DataSourceRequest] DataSourceRequest request)

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 20 May 2021, 12:19 PM

Hi Serge,

For the first two questions - you can handle the Edit event and check if the edited model is new or not using the isNew() method. Based on the outcome you can change the Title of the window and set an editor to be readonly:

.Events(ev->ev.Edit("onEdit"))

<script>
function onEdit(e){
              var editWindow = e.container;
              if(e.model.isNew()){
                $(editWindow).parent().find('span.k-window-title').text("Add");
              } else {
              	var ddl = $('input[name="Category"]').getKendoDropDownList();
                ddl.readonly();
              }
            }
</script>

Here is a sample dojo demonstrating the above.

In regards to the third question you can set default values for the newly created items via the .DefaultValue() configuration for the model. You can read more on this here. In the Grid Custom Editor example you will note the DefaultValue set for the Category property. Alternatively, you can handle the BeforeEdit event of the Grid, for example, and use the set method to set value for a model field. Here is a dojo demonstrating this approach.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 21 May 2021, 07:19 AM

I see, however i talk about the server side. If "new" there is a server logic, if "edit", another server logic, I mean, why the server action is only for "post", not as well for "get" request?
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 21 May 2021, 07:23 AM

DefaultValue() server side is not always OK, because is not dynamic, is evaluated only once per application lifetime, with an empty model, and if the initial value should be dependent on the model, or be, by eg, a random color (should be estimated at every popup apparition) that will not work...
Aleksandar
Telerik team
commented on 25 May 2021, 01:08 PM

Indeed, the model for the Grid is defined upon initialization of the component and what you are looking for is not currently supported. If you need to set dynamic values for model fields I suggest trying the second approach suggested above - handle the beforeEdit event, fetch the desired values and set them to the respective model fields. 
Tags
DropDownList Grid Window
Asked by
serge
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Aleksandar
Telerik team
Share this question
or