2013-03-05 2 views
0

"자산"목록을 표시하고 Google지도에 동일한 애셋을 표시하려면 KoGrid를 사용하고 싶습니다. 사용자가지도에서 핀을 클릭하면 목록의 해당 자산이 스크롤되어 맨 위에 표시됩니다. 보너스 : 이미 볼 수 있다면 아무 것도하지 마십시오.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 
    } 
}]