【发布时间】:2018-07-01 23:14:14
【问题描述】:
我正在使用数据表和角度数据表。 如何检测数据表中的双击事件并获取行数据? 我找到了下面的代码,但我需要它的角度。
$(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>';
};
//...
});
});
【问题讨论】:
-
你在使用 angularjs 1 吗?
-
@Sathiyaraj 是的,angularjs 1.6.6
-
能贴出代码吗?
-
@Sajeetharan 我没有我要问的双击事件的角度代码。我将编辑我的问题标题。
标签: javascript angularjs angular-datatables