Richard
Richard

Reputation: 27546

Is there a scrollIntoView technique for kendoGrid

I have a kendoGrid displaying a data source that has 200 rows and 50 columns. There are vertical and horizontal scrollbars, which is desired.

How can I cause the grid to scroll into view a specific column, row or row&column ?

Two use cases are:

  1. Column name Z selected from a menu, jump to column Z (scroll it into view)
  2. Grid with data source is FOO is scrolled about until Column X is left most column in view. The grid then replaced with a new one whose data source is BAR. If BAR contains a column X then I want to scroll it into view.

Thanks, Richard

Upvotes: 0

Views: 1963

Answers (1)

OnaBai
OnaBai

Reputation: 40887

The very first thing that you need is finding the position of the cell. If you know the number of the row and the column you can do:

var col = 30;
var row = 100;
var pos = $("tr:nth(" + (row - 1) + ")", grid.tbody).find("td:nth(" + (col - 1) + ")").position();

Then you have to scroll and you can go directly using:

$(grid.tbody).closest(".k-grid-content").scrollTop(pos.top).scrollLeft(pos.left);

or animate it using:

$(grid.tbody).closest(".k-grid-content").animate({
    scrollTop : pos.top,
    scrollLeft: pos.left
}, 2000);

Upvotes: 1

Related Questions