2010-06-16 20 views
4

如何獲取dojox.enhancedGrid的選定行對象? 我正在使用selectionMode:'single' 與單選按鈕。dojox.enhancedGrid獲取所選行

dijit.byId("gridViewWidget").selection.selectedIndex 返回rowIndex。 但如何獲得該索引的rowObject? 我可以得到rowNode()但我需要的是該行的id列的值。

它可以馴化由rowNode()返回的HTML DOM但是有沒有簡單的方法?

我目前使用dijit.byId("gridViewWidget").store._dataArray[i]並傳遞返回的索引。雖然這工作似乎_dataArray是一個私人財產。 所以使用安全嗎?

回答

5

我是新來的道場我自己,但這應該是有用的,如果不是完全正確的。首先,dojox.grid.enhancedGrid是建立在dojox.grid.DataGrid頂部,因此,請檢查這裏的文檔:給定索引

  • grid.selection.getSelected()返回在

    dojox.grid.DataGrid Documentation

    • grid.getItem(idx)回到店裏「項」所選項目排列

    您應該能夠使用其中任何一種來獲得你想要的物品。

  • +0

    嗯我試過了但是沒有選擇對象上名爲'getItem(idx)'或'getSelected()'的這種方法。 我對數據網格和增強網格的選擇對象是不同的。 – 2010-06-18 16:33:54

    +0

    嗯,那可能是。就像我說的那樣,我沒有專家......而且文件也是誤導性的......好運! – Dfowj 2010-06-18 21:29:46

    0

    使用聲明標記,你可以做這樣的事情(從內存中,可能需要調整是功能性):

    <script type="text/javascript"> 
    function formatThisColumn(rowIndex, rowObject) { 
        if (rowObject == null) return; 
        field = rowObject.i.fieldName; 
        return field; 
    } 
    </script> 
    <div dojoType="dojo.data.ItemFileReadStore" id="store" jsid="jsonStore" url="test.json"></div> 
    <table dojoType="dojox.grid.EnhancedGrid" id="gridNode" jsid="grid" store="store"> 
    <thead> 
    <tr> 
        <th get="formatThisColumn">A Computed Column</th> 
    </tr> 
    </thead> 
    </table> 
    

    注意「formatThisColumn」功能:這得到每行至少調用一次在DataGrid ,並獲得行(JSON項目內)和包含'當前'項目(使用'我'索引)的對象的索引。當數據網格被渲染時,這將爲您提供JSON響應的原始值。