2014-10-19 40 views
0

我创建了一个从json数据中读取url的kendo网格。下面是代码,它工作正常ajax调用后重新加载kendo网格

$('#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"}],   
}); 

现在在同一页面,我有一点点的形式,通过Ajax调用插入新的数据到数据库中的PHP方法(IM与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(); 
    } 
}); 

在数据库中创建一个新记录也可以正常工作,但问题是之后我想用新信息重新加载网格,或许再次阅读我应该更改的json url。我尝试了很多东西,比如

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

但是没什么,我是用剑道的noob ...任何人都可以帮我吗?谢谢所有

+1

您不需要再次设置URL。 ('#grid')。data('kendoGrid')。dataSource.read();应该管用。你确定数据库中插入了新行吗? – 2014-10-20 05:44:35

+0

是的确定如果我再次加载网站的新行出现在网格中。感谢您的帮助 – sklapez 2014-10-20 13:17:38

回答

1

你已经在dataSource读取设置中有默认的HTTP方法'GET',并且它正在缓存查询数据。溶液之一:

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

解决方法二:

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

,然后只用dataSource.read()方法。

+0

感谢您的帮助,我已经尝试过这两种解决方案,但没有,仍然是相同的... – sklapez 2014-10-20 13:19:34

+1

它真的是weard :(你可以试试这个:var dSource = $('#grid')。data '(';');(new Date()。getTime());' 'dSource''dataSource;' 'dSource.transport.options.read.url =“http:// localhost/CoreProcess/proceso/getusers? .read();' – 2014-10-20 16:29:49

2

终于我修好了它,它没有任何与剑道看到。我使用Yii框架,并保存数据库中的记录后,你必须刷新它,所以新的信息可以加载,一个简单的错误,但我怎么新与剑道我不知道如果它是错的或正确的。

简单指令

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

足以我

感谢所有支持我会继续使用这个奇妙的工具。请参见下面的问题xD

+0

这就是我想要的。谢谢分享... – 2016-06-10 12:57:41