2013-03-05 24 views
0

我想使用KoGrid顯示「資產」列表,並在Google地圖中顯示相同的資產。當用戶點擊地圖上的銷釘時,列表中的相應資產應向下滾動以顯示在頂部。獎勵:如果已經在視野範圍內,請不要做任何事情。KoGrid - 自動滾動至選中

我之前在不同的列表上完成了這項工作,並且與排序和過濾的交互導致了我一段時間的問題(每次排序或過濾時我都必須重新計算出資產的索引)。

我可以用koGrid做這個嗎?在切換到這個網格之前,我需要弄清楚這一點。 任何例子或幫助表示讚賞。

回答

4

我想你將需要得到一個參考網格,並調用網格$viewport.scrolltop方法。注意:我沒有測試這個,我只是基於我做過的類似的東西寫的。

plugins: [{ 
    onGridInit: function (g) { 
// maybe add a method to your view model 
     viewModel.scrollTo = function (index, key) { // index of item in filter data, key is something i made up 
      if (index > g.filteredData().length - 8) { // 8 is the default excess_rows value in kogrid 
       g.$viewport.scrollTop(g.$viewport.scrollTop() + (g.config.rowHeight * index)); 
      } 
      // if you want to select the row (set time out because ko grid dynamically creates the rows rendered in the grid) 
      setTimeout(function() { 
       var i = ko.utils.arrayFirst(g.renderedRows(), function (row) { 
        // some function that finds the entity 
        return row.entity.key === key; 
       }); 

       if (i) { 
        g.selectionService.ChangeSelection(i) // this will select the row 
       } 
      }, 100); 

     }// assume self is your view model 
    } 
}]