Is there any way to read the dojo Objectstore and convert it as JS array object

458 views Asked by At

Looking for a way to read the all the rows from DOJO enhancedgrid ObjectStore as JS Array object.

OnRowClick, I need to get the all items as an array. Here is the sample code:

Layout, Id are defined in another methods. Id is first header.

IN the following code, store is dataStore.

function constructEnhancedGrid(jsObject) {
require(
    ["dojo/store/Memory", "dojo/data/ObjectStore",
        "dojox/grid/EnhancedGrid",
        "dojox/grid/enhanced/plugins/Pagination", "dojo/domReady!"
    ],
    function(Memory, ObjectStore, EnhancedGrid, Pagination) {

        jsGlobalObject = jsObject;
        jsObject = JSON.parse(jsObject);

        var objectStoreMemory = new Memory({
            data: jsObject,
            idProperty: [tableheaders[0]]
        });

        dataStore = new ObjectStore({
            objectStore: objectStoreMemory
        });

        constructEnhancedGridlayout(tableheaders);

        if (typeof rtGrid === "undefined") {
            rtGrid = new EnhancedGrid({
                store: dataStore,
                structure: enhancedGridLayout,
                plugins: {
                    pagination: {
                        pageSizes: ["10", "25", "50", "100"],
                        description: true,
                        sizeSwitch: false,
                        pageStepper: true,
                        gotoButton: false,
                        maxPageStep: 5,
                        position: "top",
                        defaultPageSize: 20
                    }
                },

            }, "rtGrid");
            rtGrid.startup();
        } else {
            rtGrid.setStructure(enhancedGridLayout);
            rtGrid.setStore(dataStore);
            rtGrid.currentPage(1);
            rtGrid.render(dataStore);
            rtGrid.startup();
        }
        dojo.connect(rtGrid, "onRowClick", function(e) {
            dataStore.fetch({
                query: {},
                onComplete: function(items) {
                    var resArray;
                    dataStore.objectStore.get().then(function(result) {
                        resArray = result;
                    });
                }
            });
        });
    });
}
1

There are 1 answers

10
soeik On BEST ANSWER

Updated answer

Initially I assumed that you use JsonRest, but now I see that you use Memory object to populate your datagrid. Instance of Memory has attribute data with an array of data it contains. You can access it directly in you code.

    grid.on("RowClick", function (e) {

            var data = this.store.objectStore.data;

        })
    });