dxDataGrid-如何刷新小部件 [英] dxDataGrid - How to refresh the widget
问题描述
单击ı时,将不起作用.如果要添加到数据库,请按按钮进入屏幕.但是没有更新.我用ajax创建了一个数据网格.我也在ViewModel中编写了刷新功能,这可能是不续约的原因.我的数据是json.
When ı clicked button, not working refresh.If the purpose is to add to the database buton button press to come to the screen. But is not updating. I created a datagrid with ajax. I also wrote the refresh function in ViewModel.What may be the reason for not renewing. My data is json.
$.ajax({
type: "GET",
url: "https://js.devexpress.com/Demos/WidgetsGallery/data/orderItems"
success: function (msg, result, status, xhr) {
var obj = jQuery.parseJSON(msg);
$("#gridContainer").dxDataGrid({
dataSource: obj,
filterRow: {
visible: true}});}});
var viewModel = {
refresh: function () {
var dataGrid = $('#gridContainer').dxDataGrid('instance');
dataGrid.refresh();}};
return viewModel;
<div data-options="dxView : { name: 'dd',disableCache: true } " >
<div data-bind="dxCommand: { icon: 'refresh', id: 'save', onExecute: refresh }"></div>
<div data-options="dxContent : { targetPlaceholder: 'content' } " >
<div id="gridContainer"></div>
</div>
</div>
推荐答案
正如Alex所提到的,您的ajax仅发生一次.因此,最好使用数据源配置对象加载数据:
As Alex mentioned, your ajax happens only one. So, it's better to use the DataSource configuration object to load data:
var dataSource = {
load: function() {
var items = $.Deferred();
$.ajax({
type: "GET",
url: "https://js.devexpress.com/Demos/WidgetsGallery/data/orderItems",
success: function(result) {
items.resolve(result.items);
}
});
return items.promise();
}
};
$("#gridContainer").dxDataGrid({
dataSource: dataSource,
//...
});
然后,如果调用dxDataGrid的refresh()
方法,则将重新加载数据源.
Then, if you call the refresh()
method of dxDataGrid, data source will be reloaded.
请注意,刷新方法如果您的数据源是动态变化的,则很有用.
Pay attention, the refresh method is useful if your data source is changing dynamically.
这篇关于dxDataGrid-如何刷新小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!