2

I am using OnDemandGrid virtuall scrolling with JSONRest store.

         require([
        "dojo/request",
        "dojo/store/Memory",
        "dgrid/OnDemandGrid",
        "dojo/store/JsonRest"
                    ], function (request, Memory, OnDemandGrid,JsonRest) {

            var jsonstore = new JsonRest({target: url , idProperty: "id"});

            // Create an instance of OnDemandGrid referencing the store
            var grid = new OnDemandGrid({

                store: jsonstore,
                columns: Layout,
                minRowsPerPage : 40,
                maxRowsPerPage : 40,
                loadingMessage: "Loading data...",
                noDataMessage: "No results found."
            }, "grid");

            grid.startup();

    });

I dont know how to get the rowIndex of the cell. Can someone tell me how to find the row index?

SSayee
  • 95
  • 4
  • 10
  • 1
    Not sure what you're asking? Which rowIndex/cell are you talking about? Is it one that has been selected in the grid or are you looking for something that will tell you the row index of a particular record in the whole store vs the row index of what is displayed at any given time on your grid? – David Jul 26 '13 at 13:53
  • Like rowIndex in dojox.EnhancedGrid formatter function ,do we have anything in Dgrid? – SSayee Jul 29 '13 at 10:57
  • I'm not aware of anything in dGrid (or OnDemandGrid) which will give you a specific row index, but see my "answer" below to see if that helps you find a solution. – David Jul 29 '13 at 15:22

1 Answers1

1

You may find what you're looking for by using Selection mixin provided by dGrid. Using Selection, you can define your grid like this:

            grid = new (declare([OnDemandGrid, Selection]))({
                store: Observable(Memory({ // replace with your store of choice
                    idProperty: 'id'
                })),
                columns: { /* your columns layout */ },
                noDataMessage: 'No results found.',
                loadingMessage: 'Loading data...'
            });
            grid.startup();

In your columns object, you can define a column that uses a function called renderCell that looks like this:

            renderCell: function (object, value, node, options) {
                // Object is the row; i.e., object's properties are the column names
                // value is the value for this cell 
                // node is the DOM node of this cell
                // Not sure what 'options' refers to
            }

When a row is selected, you can retrieve the row by using the grid.selection property, which is an object that contains key/value pairs where the the ID's (based on idProperty) are the keys. The value for each key contains a boolean that indicates whether or not that particular row is selected. So, to get each selected row, you could do something like:

            for (selectedId in selection) {
                if (selection.hasOwnProperty(selectedId) && selection[selectedId] === true) {
                    var selectedRow = grid.row(selection[selectedId];

                    ... // and so on...
                }
            }

None of this specifically gives you the row index, but you may be able to figure it out from here using your browser's Development Tools (e.g., Firebug for Firefox, etc).

David
  • 393
  • 4
  • 16