gpt4 book ai didi

javascript - 如何在 Angular 数据表中获取双击事件

转载 作者:行者123 更新时间:2023-11-30 20:48:54 25 4
gpt4 key购买 nike

我正在使用数据表和 Angular 数据表。如何检测数据表中的双击事件并获取行数据?我找到了下面的代码,但我需要它的 Angular 。

$(document).on("dblclick", "#myTable tr", function () {
//code here
});

html

<table datatable="tblRecipe" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" dt-instance="showCase.dtInstance" class="table table-bordered"></table>

controller.js

var app = angular.module('app', ['datatables'])
app.controller('MainController', function ($scope, $window, $http, $filter, $timeout, $compile, DTOptionsBuilder, DTColumnDefBuilder, DTColumnBuilder) {
var vm = this;
vm.dtInstance = {};
vm.Recipes = {};
vm.delete = deleteRow;
vm.edit = editRow;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
url: "/Recipes/GetAllRecipes",
type: "POST"
})
.withOption('createdRow', createdRow)
.withOption('select', true);
vm.dtColumns = [
//...
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().renderWith(actionsHtml)
];
function actionsHtml(data, type, full, meta) {
vm.Recipes[data.Id] = data;
return '<a title="View" href="javascript:void(0)" ng-click="showCase.view(showCase.Recipes[' + data.Id + '])">' +
' <i class="fa fa-eye" aria-hidden="true"></i>' + '</a>' + '<a title="Edit" href="javascript:void(0)" ng-click="showCase.edit(showCase.Recipes[' + data.Id + '])">' +
' <i class="fa fa-pencil"></i>' + '</a>' + '<a title="Delete" href="javascript:void(0)" ng-click="showCase.delete(showCase.Recipes[' + data.Id + '])" )"="">' + ' <i class="fa fa-trash-o"></i>' + '</a>';
};
//...
});
});

最佳答案

I am using datatables and angular-datatables. How do I detect a double click event in the datatable and get the row data? I found the code below but I need it in angular.

DataTables jQuery,Angular-DataTables 只是使它们在 AngularJS 上下文中工作的指令。除非你正在渲染“Angular 方式”,即 datatable="ng" 你需要 $compile 回调中的表,行或每个单元格,如果你想要任何工作指令。

只需像使用 jQuery DataTables 一样使用委托(delegate)事件处理程序,并通过 dtInstance 获取数据,其中包含 API 实例:

$('#tableId').on('dblclick', 'tbody tr', function() {
console.log( $scope.dtInstance.DataTable.row(this).data() )
})

更新: http://plnkr.co/edit/PdrKxxxsDFdNSzgf8c07?p=preview

关于javascript - 如何在 Angular 数据表中获取双击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48396558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com