We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Got error building grid

Hi, 
I am trying to build a grid with next code:

$.ajax({
        url: "/Contrato/Beneficiarios?idContrato=" + idContrato,
        type: "GET",
        cache: true,
        success: function (result) {
            var x = result.listaBeneficiarios;
            alert("hola");
            var grid = new ej.grids.Grid({
                datasource: result.listaBeneficiarios,
                toolbar: ["Add", "Edit", "Delete"],
                columns: [
                    { field: "Id", isPrimaryKey: true, isIdentity: true, visible: false },
                    { field: "IdTiposIdentificacion", headerText: "Tipo id", foreignKeyField: "IdTiposIdentificacion", foreignKeyValue: "Nombre", dataSource: result.listaTiposId },
                    { field: "NumeroId", headerText: "Numero id" },
                    { field: "PrimerNombre", headerText: "Primer nombre", visible: false },
                    { field: "SegundoNombre", headerText: "Segundo nombre", visible: false },
                    { field: "PrimerApellido", headerText: "Primer apellido", visible: false },
                    { field: "SegundoApellido", headerText: "Segundo apellido", visible: false },
                    { field: "NombreCompleto", headerText: "Nombre" },
                    { field: "TelefonoMovil", headerText: "Celular" },
                    { field: "Email", headerText: "Email" },
                    { field: "IdSede", headerText: "Sede", foreignKeyField: "IdSede", foreignKeyValue: "Nombre", dataSource: result.listaTiposId },
                    { field: "WelcomeDay", headerText: "Welcome day", editType: "datetimepickeredit" },
                    { field: "Observaciones", headerText: "Obs" }
                    //{ headerText: "Enviar email", width: "160", commands(comandos) }
                ],
                editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: "Dialog" },
                locale: "es-CO",
                load: "load"

            });
            grid.appendTo("#grdBeneficiarios");
            
        },
        error: function (jqXHR, textStatus, error) {
            alert(error);
        }
    });

but I am getting an error in javascript, image attached.

Second question: Is there any way to manage remoteserveradapter in javascript ( no textscript) ?



Attachment: Error_b41c1e66.zip

3 Replies

MS Madhu Sudhanan P Syncfusion Team March 13, 2019 01:08 AM

Hi Juan, 

Thanks for contacting Syncfusion support. 

Query 1 : I am getting an error in javascript, image attached. 
We have analyzed the codes which you have shared with us. We could see that you have not defined the handler function for the “load” event which you have bind to Grid. This is the cause of the error you are facing. We suggest you to define a handler function for the load event as like the code below. And also ensure to use proper naming case for the “dataSource” property. 

 
        $.ajax({ 
            ... 
           success: function (result) { 
                ... 
               var grid = new ej.grids.Grid({ 
                    dataSource: result.listaBeneficiarios, 
                    ... 
                    locale: "es-CO", 
                   load: function (args) { 
                        console.log("Need to define the load event handler"); 
                    } 
 
                }); 
                grid.appendTo("#grdBeneficiarios"); 
            }, 
            ... 
       }); 
 
 
Documentations :  
 
Query 2 : Is there any way to manage remoteserveradapter in javascript ( no textscript) ? 
Based on your requirement we have prepared a “RemoteSaveAdaptor” sample with JavaScript(ES5) code. Please download the sample from the link below, 
 
Please refer the code below, 

 
<div id="Grid"></div> 
<script> 
    var data = @Html.Raw(Json.Serialize(ViewBag.DataSource)); 
    var dataSource = new ej.data.DataManager({ 
        json: data, 
        adaptor: new ej.data.RemoteSaveAdaptor(), 
        insertUrl: '/Home/Insert', 
        updateUrl: '/Home/Update', 
        removeUrl: '/Home/Delete' 
    }); 
    var grid = new ej.grids.Grid({ 
        dataSource: dataSource, 
        ... 
   }); 
    grid.appendTo("#Grid"); 
</script> 


Please get back to us if you need further assistance. 

Regards, 
Madhu Sudhanan P 



JJ Juan José March 14, 2019 01:56 PM

Thanks so much,
Now it is working


MS Madhu Sudhanan P Syncfusion Team March 15, 2019 12:21 AM

Hi Juan, 
  
Thanks for the update. 
  
Regards, 
Madhu 


Loader.
Live Chat Icon For mobile
Up arrow icon