Sandy
Sandy

Reputation: 466

dgrid - not able to keep selection mode as "single" when using a Dojo Memory/ObjectStore as store

I m not able to keep the selectionMode as "single" or "extended". Only multiple selection of rows is happening, when I m using a dojo Memory/ ObjectStore as store.

    require([
    "dojo/_base/declare",
    "dojo/request",
    "dojo/data/ObjectStore",
    "dojo/store/Memory",
    "dgrid/OnDemandGrid",
    "dgrid/Keyboard",
    "dgrid/Selection",
    "dojo/DeferredList",
    "dojo/domReady!"
    ],
    function (declare, request, ObjectStore, Memory, OnDemandGrid, Keyboard, Selection, DeferredList) {

        var ddstore;


        claimDef = dojo.xhrGet({
            url: "pageToGetData.aspx",
            handleAs: "json",
            load: function (res) {
                // Resolve when content is received 
                ddstore = new Memory({ data: res });

            }
        });


        var defs = new dojo.DeferredList([claimDef]);
        defs.then(function (results) {
            // Create a new constructor by mixing in the components
            var CustomGrid = declare([OnDemandGrid, Keyboard, Selection]);

            claimAccountsGrid = new CustomGrid({
                columns: [
                { label: "Label1", field: "Field1" },
                { label: "Label2", field: "Field2" },
                { label: "Label3", field: "Field3" },
             ]

            }, "claimAccountsGrid");
            claimAccountsGrid.setStore(ddstore);


        });
    });

But, when I m hard-coding the same data that is obtained from that page, I m able to get the default selectionMode as "extended".(This way):

    require([
    "dojo/_base/declare",
    "dojo/request",
    "dojo/data/ObjectStore",
    "dojo/store/Memory",
    "dgrid/OnDemandGrid",
    "dgrid/Keyboard",
    "dgrid/Selection",
    "dojo/DeferredList",
    "dojo/domReady!"
    ],
    function (declare, request, ObjectStore, Memory, OnDemandGrid, Keyboard, Selection, DeferredList) {
        pageNo = 1;
        var ddstore;


        claimDef = dojo.xhrGet({
            url: "pageToGetData.aspx",
            handleAs: "json",
            load: function (res) {
                // Resolve when content is received 
                ddstore = //new Memory({ data: res });

                [
                { "Field1": "value1", "Field2": null, "Field3": "1" },
                { "Field1": "value2", "Field2": null, "Field3": "1"}
                ];
            }
        });


        var defs = new dojo.DeferredList([claimDef]);
        defs.then(function (results) {
            // Create a new constructor by mixing in the components
            var CustomGrid = declare([OnDemandGrid, Keyboard, Selection]);

            claimAccountsGrid = new CustomGrid({
                columns: [
                { label: "Label1", field: "Field1" },
                { label: "Label2", field: "Field2" },
                { label: "Label3", field: "Field3" },
             ]
            }, "claimAccountsGrid");
            //claimAccountsGrid.setStore(ddstore);
            claimAccountsGrid.renderArray(ddstore);

        });
    }); 

Upvotes: 0

Views: 854

Answers (1)

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

Since you haven't shown the actual data I can't be 100% certain, but this is something that happens if you fail to properly ensure your items have unique identifiers (or, if the identifier field is something other than id, you forgot to set idProperty on the Memory store to inform it of what field to look at).

See also https://github.com/SitePen/dgrid/issues/61

Upvotes: 2

Related Questions