在组合框值更改时使用新的存储值更新/刷新dojo数据网格 [英] updating/refreshing dojo datagrid with new store value on combobox value changes
问题描述
我的页面上有一个组合框和一个数据网格。当用户更改组合框值时,我必须使用新选择的父级的子级详细信息更新网格。如何使用Dojo组合框和datagrid实现此目的。
I have a combo box and a datagrid in my page. when the user changes the combo box value i have to update the grid with children details of newly selected parent. How can I achieve this using Dojo combo box and datagrid.
以下代码段对我不起作用。当我在带有新json数据的网格上使用setStore方法时。
the following code snippet not working for me. when I use setStore method on the grid with new json data.
<div dojoType="dojo.data.ItemFileReadStore" jsId="store" url="/child/index/"></div> // grid store
<div dojoType="dojo.data.ItemFileReadStore" jsId="parentStore" url="/parent/index/"></div> // combo box store
//组合框
<input dojoType="dijit.form.ComboBox" value="Select" width="auto" store="parentStore" searchAttr="name" name="parent" id="parent" onchange="displayChildren()">
// MY GRID
//MY GRID
<table dojoType="dojox.grid.DataGrid" jsId="grid" store="store" id="display_grid"
query="{ child_id: '*' }" rowsPerPage="2" clientSort="true"
singleClickEdit="false" style="width: 90%; height: 400px;"
rowSelector="20px" selectionMode="multiple">
<thead>
<tr>
<th field="child_id" name="ID" width="auto" editable="false"
hidden="true">Text</th>
<th field="parent_id" name="Parent" width="auto"
editable="false" hidden="true">Text</th>
<th field="child_name" name="child" width="300px" editable="false">Text</th>
<th field="created" name="Created Date" width="200px"
editable="false" cellType='dojox.grid.cells.DateTextBox'
datePattern='dd-MMM-yyyy'></th>
<th field="last_updated" name="Updated Date" width="200px"
editable="false" cellType='dojox.grid.cells.DateTextBox'
datePattern='dd-MMM-yyyy'></th>
<th field="child_id" name="Edit/Update" formatter="fmtEdit"></th>
</tr>
</thead>
</table>
//父组合框的更改方法,其中我正尝试从中重新加载新数据
//onchange method of parent combo box in which i am trying to reload the grid with new data from the server.
function displayChildren() {
var selected = dijit.byId("parent").attr("value");
var grid = dojo.byId('display_grid');
var Url = "/childsku/index/parent/" + selected;
grid.setStore(new dojo.data.ItemFileReadStore({ url: Url }));
}
但是它并没有使用新内容更新网格。我不知道每次用户更改组合框值时如何刷新网格。
But it's not updating my grid with new contents. I don't know how to refresh the grid every time users changes the combo box value.
如果能同时获得ItemFileReadStore和ItemFileWrireStore的解决方案,我将感到很高兴。
推荐答案
我认为您缺少 fetch()步骤。这是我编写事件处理程序的方式:
I think you're missing the fetch() step. Here is how I would code your event handler:
function displayChildren() {
var selected = dijit.byId("parent").attr("value");
var store = new dojo.data.ItemFileWriteStore({ // Read or Write, no difference
url: "/childsku/index/parent/" + selected
});
// Fetch the grid with the data
store.fetch( {
query : {},
onComplete : function(items, request) {
var grid = dojo.byId('display_grid');
if (grid.selection !== null) {
grid.selection.clear();
}
grid.setStore(store);
},
error: function(message, ioArgs) { alert(message+"\nurl: "+ioArgs.url); }
});
}
这篇关于在组合框值更改时使用新的存储值更新/刷新dojo数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!