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.
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
//combo box
<input dojoType="dijit.form.ComboBox" value="Select" width="auto" store="parentStore" searchAttr="name" name="parent" id="parent" onchange="displayChildren()">
//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.gr开发者_Go百科id.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.
I would be glad if I get the solution for both ItemFileReadStore and ItemFileWrireStore.
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); }
});
}
精彩评论