dojox.grid.enhancedgrid删除行,从服务器删除但不从网格删除

时间:2012-10-12 13:21:24

标签: javascript datagrid dojo

我的名为unitsGrid的enchancegrid运行正常。我可以添加行和删除行,但是当我删除行时,我遇到了一些我无法弄清楚的问题,因此当删除时行不会从我的unitsGrid中消失。我现在一直在看代码几个小时,但我似乎无法弄明白。 提前谢谢。

dojo.connect(unitsGrid, "onRowClick", unitsGrid, function(evt, rowIndx, fieldIndx){

            var idx = evt.rowIndex;
            var item = this.getItem(idx);
            var id = unitsGrid.store.getValue(item, "id");

            if(evt.cellIndex == 3) {
                var con = confirm("Är du säker på att du vill radera denna transaktion?");
                if(con == true) {
                    dojo.xhrPost({
                        url: url,
                        content: {
                            id: id
                        },
                        handleAs: "text",
                        load: function(data) {
                            var selectedRows = grid.selection.getSelected();
                            if (selectedRows.length) {
                            // Iterate through the list of selected items.
                            // The current item is available in the variable
                            // "selectedItem" within the following function:
                                dojo.forEach(selectedRows, function(selectedItem) {
                                    if (selectedItem !== null) {
                                        // Delete the item from the data store:
                                        try {
                                            unitsGrid.store.deleteItem(selectedItem);
                                        }
                                        catch(error) {
                                            console.log("Returned error: " + error.message);
                                        }
                                    } // end if
                                }); // end forEach
                            } // end if
                            console.log("Return value: " + data);
                        },
                        error: function(error) {
                            console.log(error);
                        }
                    }); // end xhrPost
                }
            }

        });

1 个答案:

答案 0 :(得分:1)

只需调用dijit.byId('unitsGrid')。removeSelectedRows();

相关问题