【问题标题】:updating/refreshing dojo datagrid with new store value on combobox value changes使用组合框值更改时的新存储值更新/刷新 dojo 数据网格
【发布时间】:2011-02-15 04:54:06
【问题描述】:

我的页面中有一个组合框和一个数据网格。当用户更改组合框值时,我必须使用新选择的父级的子级详细信息更新网格。如何使用 Dojo 组合框和数据网格实现此目的。

以下代码 sn-p 不适合我。当我在带有新 json 数据的网格上使用 setStore 方法时。

<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()"> 

//我的网格

<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方法,我试图用来自服务器的新数据重新加载网格。

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 }));
            }

但它不会用新内容更新我的网格。我不知道每次用户更改组合框值时如何刷新网格。

如果我能同时获得 ItemFileReadStore 和 ItemFileWrireStore 的解决方案,我会很高兴。

【问题讨论】:

    标签: datagrid dojo refresh


    【解决方案1】:

    我认为您缺少 fetch() 步骤。以下是我将如何编写您的事件处理程序:

    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); }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      相关资源
      最近更新 更多