2

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;
                    });
                }
            });
        });
    });
}
Ajay Kumar
  • 71
  • 8

1 Answers1

1

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;

        })
    });
soeik
  • 905
  • 6
  • 15
  • grid.store.objectStore.get() is not returning all the objects. – Ajay Kumar Feb 02 '18 at 12:31
  • @AjayKumar, sorry for confusing. get() returns promise and you can get necessary data from it. I'll update my answer. – soeik Feb 02 '18 at 12:49
  • Actually get() method is not returning any object, Here is the error for the above code. "Unable to get property 'then' of undefined or null reference" But get(id) is giving an object. It would be great, if I get all objects at once without iterating. – Ajay Kumar Feb 02 '18 at 14:47
  • @AjayKumar Could you add some code in your question? How you create your grid and where you are trying to get result. – soeik Feb 02 '18 at 14:51
  • Thanks for the quick reply. My point here is this.store.objectStore.get() always is returning "undefined". – Ajay Kumar Feb 02 '18 at 16:13
  • According to the Dojo 1.10 documentation [here](https://dojotoolkit.org/reference-guide/1.10/dojo/store.html#dojo-store) there is no `get` function which takes no parameters as shown in this answer. There is only a `get(id)` function which takes an id of some specific object to retrieve. Is it necessary to get a list of all ids and iterate them to call `get` on each? – takendarkk Feb 02 '18 at 16:22
  • @csmckelvey I tried it with dojo 1.10 and it works. Need to look into source to clarify. – soeik Feb 02 '18 at 17:08
  • @kirill-stepanov, I am using 1.10.4, Can you please tell me the complete version . And as per the documentation of 1.10, this method does not exist. Will raise as a defect on DOJO to find out these discrepancies. – Ajay Kumar Feb 05 '18 at 19:28
  • @AjayKumar Because it's not a method of ObjectStore class, but method of store.objectStore. It looks confusing, but I in my example use JsonRest as store, so when you create instance of your ObjectStore you pass this object as argument. What kind of store are you using to populate a grid? Could you please post complete code of how you cretae store and instance of grid. – soeik Feb 06 '18 at 08:20
  • @AjayKumar, well now I understood why you have not get() method. I updated my answer, hope now it will work for you. – soeik Feb 06 '18 at 16:22