简体   繁体   English

Ajax调用后重新加载Kendo Grid

[英]Reloading Kendo Grid after ajax call

I have created a kendo grid that reads from a url with json data. 我创建了一个Kendo网格,该网格从具有json数据的url中读取。 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) 现在在同一页面中,我有一个小表格,可通过对php方法的ajax调用将新数据插入数据库(即与yii框架一起使用)

$.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. 在数据库中创建新记录的工作也很好,但问题是在那之后我想用新信息重新加载网格,也许再次读取我应该更改的json url。 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. 我使用的是Yii框架,在数据库中保存记录后,您必须刷新它,以便可以加载新信息,这是一个简单的错误,但是我对Kendo的了解如何,我不知道这是对还是错。

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 下一步看问题xD

You've got default HTTP method 'GET' in dataSource read setting and it's caching the query data. 在dataSource读取设置中,您已经有了默认的HTTP方法'GET',并且它正在缓存查询数据。 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. 然后只需使用dataSource.read()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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