sklapez
sklapez

Reputation: 21

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

Upvotes: 0

Views: 8217

Answers (2)

sklapez
sklapez

Reputation: 21

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

Upvotes: 2

Jarosław Kończak
Jarosław Kończak

Reputation: 3407

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.

Upvotes: 1

Related Questions