Search code examples
javascriptdojodgrid

Dojo grid refresh and scroll position


I have a Grid in Dojo,

var myGrid = new (declare([Grid, DijitRegistry]))({
    store: myStore, // this is a Observable(Memory())
    columns:[
        {field: "field1", label: "A", sortable: false},
        {field: "field2", label: "B", sortable: false},
        {field: "field3", label: "C", sortable: false},
        {field: "field4", label: "D", sortable: false},
        {field: "field5", label: "E", sortable: false}
    ],
    selectionMode: "single",
    cellNavigation: true,
    queryOptions: {
        sort:[{attribute: "field1", descending: true}]
    }
},
    myDomRef
);

At times I need to refresh the grid

myGrid.refresh();

This grid has a scrollbar at the right and I would like to retain the position of the scrollbar. But when I do a refresh, it scrolls back to the top.

How could I retain the scroll position?


Solution

  • If you're using OnDemandGrid, it supports a keepScrollPosition property, which you can either define on the grid instance to influence all refresh calls, or pass specifically when calling refresh (e.g. grid.refresh({ keepScrollPosition: true })).