2013-11-21 60 views
3

我將如何去實現ng-Grid中的雙擊事件?更具體地說,我想雙擊打開彈出式模態(Angular UI Modal)進行編輯。ngGrid雙擊一行打開彈出窗口以編輯一行

有關如何做到這一點的任何想法?

+0

添加ngDblclick您rowtemplate。請參閱此處的評論:http://developer.the-hideout.de/?p=113 – AardVark71

回答

-1

我不知道,但是這可能會幫助你, http://plnkr.co/edit/SUQnUhX0wyi9UDMc4Vpl?p=preview

+0

最好在答案中包含鏈接的詳細信息,而不是發佈鏈接,因爲鏈接可能會斷開無實質的答案。如果您願意,您仍然可以擁有鏈接,但答案必須包含相關信息。 –

+0

這種情況似乎發生了。這個plnkr現在似乎與dbl無關。 – boatcoder

+0

Downvote對於這個答案有點苛刻,因爲Mark0978和Rodolfo Jorge都展示瞭如何打開Pritish問的彈出窗口!我已經瞭解到,你必須回答整個問題,不僅是你認爲是困難的部分;-)。 @ Mark0978所以你是正確的,它與dbl click nggrid沒有關係,但它顯示瞭如何打開一個彈出窗口:-)。用戶16應該將他的答案與其他人的答案結合起來,並且pritish可以將其標記爲答案! – Sebastian

0

從關於該問題的評論的鏈接通過@ AardVark71 Add Doubleclick Behavior to ng-grid

以下Javascript的文件從您的應用程序添加到一些目錄訪問並且不要忘記在啓動過程中加載它。

/* 
DoubleClick row plugin 
*/ 

function ngGridDoubleClick() { 
    var self = this; 
    self.$scope = null; 
    self.myGrid = null; 

    // The init method gets called during the ng-grid directive execution. 
    self.init = function(scope, grid, services) { 
     // The directive passes in the grid scope and the grid object which 
     // we will want to save for manipulation later. 
     self.$scope = scope; 
     self.myGrid = grid; 
     // In this example we want to assign grid events. 
     self.assignEvents(); 
    }; 
    self.assignEvents = function() { 
     // Here we set the double-click event handler to the header container. 
     self.myGrid.$viewport.on('dblclick', self.onDoubleClick); 
    }; 
    // double-click function 
    self.onDoubleClick = function(event) { 
     self.myGrid.config.dblClickFn(self.$scope.selectedItems[0]); 
     self.$scope.$apply(); 
    }; 
} 

定義一個函數來處理雙擊和更新網格選項,如下所示:

$scope.myDblClickHandler = function(rowItem) { 
// rowItem is actually the entity of the row ... 
} 

$scope.gridOptions = { 
    // other config here... 
    dblClickFn: $scope.myDblClickHandler, 
    plugins: [ngGridDoubleClick] 
} 

此功能並不一定是在$範圍這個工作。

+0

此方法假定您已爲行選擇啓用。 –

+0

我可能會錯過一些東西,是否有理由這麼做,而不是像@ Rodolpho的回答那樣使用'ng-dblclick'? – jwg

+0

當我寫我的時候,他的回答並不存在。我正計劃儘快嘗試他的答案,看看它是否比我的更好。 – boatcoder

8

在NG-電網2.0.11,做一個簡單的調用到NG-DBLCLICK指令行的模板

$scope.gridOptions = { 
    data: 'gdDtA', 
    rowTemplate: '<div ng-dblclick="foo(row)" ng-style="{\'cursor\': row.cursor, \'z-index\': col.zIndex() }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}" ng-cell></div>',   
}; 

$scope.foo = function(r) { 
    console.log(r); 
} 

見:https://github.com/angular-ui/ng-grid/wiki/Templating

+0

請注意,即使您使用雙擊來編輯單元格,也可以執行此操作。該函數將被調用,並且該單元格(如果可編輯的話)將打開輸入框。如果你有一個可編輯的條件,並且希望某些單元格彈出某些內容,而其他單元格可以正常編輯,這很有用。 – jwg

+0

不知道我錯過了這張貼,我會試試看,而不是我的解決方案。 – boatcoder

相關問題