Dialog editing in EJ2 only works sometimes - Dialog form displays just #dialogtemplate only

Hi,

I am trying to build a solution (PoC) using EJ2 grid. I am getting data from MySQL DB thru' PHP page.

Strangely, when I fetch data from one sample table, the edit->dialog form displays the controls correctly. But when I fetch data from another table, (and with appropriate dialogtemplate added), the edit dialog form shows only #dialogtemplate

Attached a zip file containing:

1) dist - containing javascript / css files I am using

2) dlgorig - This is a test solution using JSON as data source

3) dlgtest - This contains the PoC. The index.html and index.js contains some commented section - this section contains code for 'working' scenario and 'not-working' scenario

4) SrbDB.sql - MySQL DB / table / data creation script



Attachment: tosupport_7e4ce516.zip


6 Replies

JC Joseph Christ Nithin Issack Syncfusion Team September 29, 2021 06:03 AM UTC

Hi Sathya, 

Thanks for contacting Syncfusion support. 

Query: Dialog editing in EJ2 only works sometimes - Dialog form displays just #dialogtemplate only 
 
Based on your query, you are facing data binding issue in your Grid application. So, we have prepared sample based on your attached code example and found everything works fine at our end. So, for your convenience we have attached the sample, please refer them for your reference. 

Code Example: 
Index.js 

actionComplete: function (args) { 
    if (args.requestType === 'beginEdit' || args.requestType === 'add') { 
      var data = args.rowData; 

      new ej.inputs.NumericTextBox( 
        { 
          value: data.EmployeeID, 
          format: 'C2', 
          placeholder: 'EmployeeID', 
          floatLabelType: 'Always', 
        }, 
        args.form.elements.namedItem('EmployeeID') 
      ); 

      // Convert Widget for the ShipCountry field 
      new ej.dropdowns.DropDownList( 
        { 
          value: data.LastName, 
          popupHeight: '300px', 
          floatLabelType: 'Always', 
          dataSource: countryData, 
          fields: { text: 'LastName', value: 'LastName' }, 
          placeholder: 'LastName', 
        }, 
        args.form.elements.namedItem('LastName') 
      ); 

      // Convert Widget for the OrderDate field 
      new ej.calendars.DatePicker( 
        { 
          value: data.BirthDate, 
          placeholder: 'BirthDate', 
          floatLabelType: 'Always', 
        }, 
        args.form.elements.namedItem('BirthDate') 
      ); 

      // Convert Widget for the ShipCity field 

      if (ej.base.Browser.isDevice) { 
        args.dialog.height = window.innerHeight - 90 + 'px'; 
        args.dialog.dataBind(); 
      } 

      // Set initail Focus 
      if (args.requestType === 'beginEdit') { 
        args.form.elements.namedItem('FirstName').focus(); 
      } else { 
        args.form.elements.namedItem('OrderID').focus(); 
      } 
    } 
  }, 
}); 

Index.html 

<script id="dialogtemplate" type="text/x-template"> 
        <div> 
            <div class="form-row"> 
                <div class="form-group col-md-6"> 
                    <div class="e-float-input e-control-wrapper"> 
                        <input id="OrderID" name="OrderID" type="text" value="${OrderID}" ${if(isAdd)} ${else} disabled ${/if} /> 
                        <span class="e-float-line"></span> 
                       <label class="e-float-text e-label-top" for="OrderID">Order ID</label> 
                    </div> 
                </div> 
                <div class="form-group col-md-6"> 
                    <div class="e-float-input e-control-wrapper"> 
                        <input id="FirstName" name="FirstName" type="text" value="${FirstName}" /> 
                        <span class="e-float-line"></span> 
                        <label class="e-float-text e-label-top" for="FirstName">FirstName </label> 
                    </div> 
                </div> 
            </div> 
            <div class="form-row"> 
                <div class="form-group col-md-6"> 
                    <input name="EmployeeID" id="EmployeeID" value="${EmployeeID}" /> 
                </div> 
                <div class="form-group col-md-6"> 
                    <input name="BirthDate" id="BirthDate" > 
                </div> 
            </div> 
            <div class="form-row"> 
                <div class="form-group col-md-6"> 
                    <input type="text" name="LastName" id="LastName" value=${if(LastName === null || LastName === undefined)} '' ${else} ${LastName} ${/if} /> 
                </div> 

            </div> 

        </div> 
      </script> 


Note: The dialog template data binding issue will be occurred when you don’t set the name and id attribute values similar to field name and field values should be available to display the values in the dialog template. So, please ensure the above things to bind the data properly in your Grid application. 

Please get back to us if you need further assistance. 

Regards, 
Joseph I.  



SA Sathya September 29, 2021 07:39 AM UTC

Hi,

Thanks for your reply.


I have already mentioned in issue, that for one (table) details, it works correctly. It does not work for other table, in spite of giving correct field name

(Refer Index.html in my attachment)

 <script id="dialogtemplate" type="text/x-template">
        <div>
            <div class="form-row" >
                <div class="form-group col-md-6">
                     <div class="e-float-input e-control-wrapper">
                        <input id="patid" name="patid" type="text" value=${if(isAdd)} '' ${else} ${patid} ${/if}  ${if(isAdd)}'' ${else} disabled ${/if}/>
                        <span class="e-float-line"></span>
                        <label class="e-float-text e-label-top" for="patid">Pat ID</label>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <div class="e-float-input e-control-wrapper">
                        <input id="Name" name="Name" type="text" value=${if(isAdd)} '' ${else} ${Name} ${/if}  ${if(isAdd)}'' ${else} ${Name}{/if}/>
                        <span class="e-float-line"></span>
                        <label class="e-float-text e-label-top" for="Name">Name</label>
                    </div>
                </div>
            </div>           
        </div>

(Refer Index.js in my attachment)

 columns: [
        { 
            field: 'patid', headerText: 'Patient ID', textAlign: 'Right', width: 100, isPrimaryKey: true,
            validationRules: { required: true
        },        
        {
            field: 'Name', headerText: 'Name', textAlign: 'Right', defaultValue: '',validationRules: { required: true }, width: 120
           
        },
        {
            field: 'MobileNumber', headerText: 'MobileNumber',
            validationRules: { required: true }, width: 140, defaultValue: ''
        },
        {
            field: 'District', headerText: 'District', textAlign: 'Right', width: 120
        }],

If still in doubt, please try to correct my source file - sections where I have marked as 'not working'


JC Joseph Christ Nithin Issack Syncfusion Team September 30, 2021 01:05 PM UTC

Hi Sathya,   
  
Please find the response for your queries below,  
  
Query – 1: “Below is the server-side code, which clearly returns the data in the format you have specified(Please note that the below code, when used to fetch data from one table, works and for another table, does not work)”  
  
We have validated your code example as below,  
  
var data = new ej.data.DataManager({  
    url: 'getData.php/?action=getData',  
    crossDomain: true  
}).executeQuery(new ej.data.Query()).then(function(e){  
   grid.dataSource = e.result;  
});  
  
  
This will act as local data binding in Grid component. We need to return the ‘result’ and ‘count’ object format when only enable DataAdaptors like URLAdaptor(on-demand concept) etc., are bound. Already, we have shared the documentation for the same in last response. So if you are not using ‘DataAdaptors’ then you need to return only JSON object as data source. Please find the below documentation links based on this for your reference,  
  
  
  
Query - 2: THE BELOW QUERY DOES NOT WORK, I.E. DISPLAYS ONLY #dialogtemplate EDIT DIALOG  
  
By default, dialogTemplate is used to display while performing CRUD action like adding/editing. Please find the demo for your reference.  
  
  
If this does not meet your requirement, could you please share the following details to validate further,  
  
  1. Explain more details about your requirement
  2. Are you facing the error while performing CRUD or initial rendering?
  3. Share the screenshot of your issue.
  4. Share the console window if you get any script error.
  5. Share the video demonstration of your issue.
  
Regards,  
Joseph I 



SA Sathya replied to Joseph Christ Nithin Issack October 1, 2021 06:24 AM UTC

Hi,


I have attached  a document of issues faced along with screenshots of code, webpage and errors. Please go through and request you to kindly help.

Thanks 


Attachment: Issue_details_with_screenshot_EJ2_grid_8b8de488.zip


SA Sathya replied to Ajith Govarthan October 5, 2021 03:51 AM UTC

Hi,

I have resolved the issue myself. (The data object was empty because form data was empty. Form was not constructed because of a syntax error in template)

The 'if' statement was repeated twice (bold, underlined text below) in 'dialog template' in HTML file which resulted in template error.

<input id="Name" name="Name" type="text" value=${if(isAdd)} '' ${else} ${Name} ${/if}  ${if(isAdd)}'' ${else} ${Name}{/if}/>

I have corrected this error and dialog template opened.

Thanks for your suggestions


AG Ajith Govarthan Syncfusion Team October 7, 2021 02:49 AM UTC

Hi Sathya, 
  
Thanks for the update. 
  
Query: I have resolved the issue myself. (The data object was empty because form data was empty. Form was not constructed because of a syntax error in template). 
  
We are happy to hear that you have found the solution at your end and thanks for sharing the solution with us. 
  
Please get back to us if you need further assistance. 
  
Regards, 
Ajith G. 
  


Loader.
Up arrow icon