Swift: Shinobi Data Grid scroll to a specific row


#1

I have two grid let say grid a and grid b.
Value of grid a is (1, 2, 3, 4, 5, … 50) and in grid b (3, 5, 10, 25) .

I need when I click row with value 10 in grid b , then grid a will automatically scroll to row with value 10 too. In UITableView there are scrollToRow to do this but I can find similar method like that in Shinobi Data Grid. How to do that? Thanks in Advance

Edit:

I have this code to make grid a go to the top when grid b is clicking :

gridA?.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true)
self.gridA?.reloadColumns(self.gridA?.columns)

But its not still solve my problem. I cant get a specific point for row with specific value.

Edit 2 :
I implement some code from UITableView but its still not working. Below my code now :

let cell = gridA?.visibleCell(atCoordinate: gridCoordinate)
var gridCenterPoint : CGPoint = (gridA?.contentOffset)
gridCenterPoint.y += gridA.frame.size.height / 2
gridA?.setContentOffset(CGPoint.init(x: 0, y: (cell?.center.y)! - 65), animated: true)

I put this code in func shinobiDataGrid(_ grid: ShinobiDataGrid!, didTapCellAtCoordinate gridCoordinate: SDataGridCoord!, isDoubleTap: Bool) . When I click value on grid b , grid a will scroll but still not in right value/same value.


How to set long of spoke line in Donut Chart
#2

Hi MrX

You are correct in using the “setContentOffset” method as the means to update the grid to display a desired row.

Regarding your second edit, the “visibleCell(atCoordinate:…)” method will only work if the cell you wish the grid to snap to is currently visible on the screen.

If it is not, we recommend calculating the Y offset of your row by adding the previous row heights together.

For example, if you wish to get to row 20 and each row is given a height of 50. The following Code would solve your issue:

let rowHeight = 50
let rowIndexToSnapTo = 20
grid.setContentOffset(CGPoint(x: 0, y: rowHeight * rowIndexToSnapTo))

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn.