简体   繁体   中英

Reloading Kendo Grid after ajax call

I have created a kendo grid that reads from a url with json data. Here is the code and it works ok

$('#grid').kendoGrid({
    dataSource: {
      transport: {
         read: {
         url: "http://localhost/CoreProcess/proceso/getusers",
         dataType: "json",
         },
         update: {
         url: "http://localhost/CoreProcess/usuario/uptdate",
         dataType: "json"
         },
         destroy: {
         url: "http://localhost/CoreProcess/usuario/delete",
         dataType: "json"
         }
     },
     pageSize: 10
     },
     pageable: {
         refresh: true,
         pageSizes: true,
         buttonCount: 5
     },
    editable: "inline",
    columns: [{ title: "Nombre", field: "NOMBRE" },
              { title: "Apellidos", field: "APELLIDOS"},
              { title: "Email", field: "EMAIL"},
              { command: ["edit", "destroy"], title: "Acciones"}],          
});

Now in the same page i have a little form that inserts new data to the database through an ajax call to a php method (im working with yii framework)

$.ajax({
    type: "POST",
    url: "http://localhost/CoreProcess/proceso/agregarparticipantes/uuid/" + uuid,
    data:
    {
    post_participante: participante,
    post_apellidos: apellidos,
    post_email: email,
    },
    success: function(result)
    {
    alert(result);
    var dSource = $('#grid').data('kendoGrid').dataSource;
    dSource.transport.options.read.url = "http://localhost/CoreProcess/proceso/getusers";
    dSource.read();
    }
});

The creation of a new record in the database also works fine but the problem is that after that i want to reload the grid with the new information, perhaps reading again the json url that i should have changed. I have tried a lot of things like

$('#grid').data('kendoGrid').dataSource.read();
$('#grid').data('kendoGrid').dataSource.refresh();

But nothing, i am noob with kendo...anyone could help me? thanks all

finally I got fix it and It had not anything to see with Kendo. Im using Yii framework and after save records in the database you have to refresh it so the new information could be loaded, a simple error but how Im new with Kendo I did not know if It was wrong or right.

The simple instruction

$('#grid').data('kendoGrid').dataSource.read();

was enough to me

Thanks all for the support I will continue using this fantastic tool. See in nexts problems xD

You've got default HTTP method 'GET' in dataSource read setting and it's caching the query data. Solution one:

read: {
    url: "http://localhost/CoreProcess/proceso/getusers",
    dataType: "json",
    type: "POST",
},

Solution two:

read: {
    url: "http://localhost/CoreProcess/proceso/getusers",
    dataType: "json",
    cache: false,
},

and then just use dataSource.read() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM