How I can differentiate in the dataInit event wether am I adding new data or editing it?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a good question! +1 from me for it.
There are no direct way to detect inside of
dataInitwhether it is called from Add or Edit form. In the same way if you use multiple editing mode (like form editing and inline editing) and multiple searching modes (advance searching dialog and the searching toolbar) there are no direct way to detect in which place the control are used.As the workaround you can use the following. You can define a variable which you can set in the different value inside of an event which will be called in both Add and Edit form before the
dataInitwill be called. To tell the trust you have not so large choice. It’s the beforeInitData event only. So you can do like followingI used recreateForm:true property additionally to be sure that on every opening of the Add or Edit grid the form created new and the
dataInitbe called.In the demo the Add form looks like
Here the
dataInitfor the “Notes” write just the text “in Add” in the corresponding control. The “Inv. No” is the field which hold the id. The corresponding<input>control of the Add/Edit form is disabled. So the user can’t make any changes. In case of “Add” dialog the method$.jgrid.randId()will be used to generate new unique id value.The corresponding Edit form are like on the picture below: