Angularjs datatable createdRow 添加 class 到特定行
Angularjs datatable createdRow add class to specific row
我正在使用 angularjs 数据表。如果某些条件为真,我想将自定义 class 添加到行中。
这是尝试过的方式:
this.dtOptions = DTOptionsBuilder.newOptions()
...
.withOption('createdRow', function (row, data, dataIndex) {
if (data.highlight) {
let el = angular.element( document.querySelector( 'tr:nth-child('+dataIndex+')' ) )
el.addClass('highlight');
}
})
...
data.highlight 对于某些行为真,因此条件正常,但 addClass 不起作用。
你不需要这么复杂的结构。由于您使用的是数据表,因此您确实有 jQuery 可用:
if (data.highlight) {
$( row ).addClass('highlight');
}
就足够了。
在 Angular 中你可以这样做。
.withOption('createdRow', function (row, data, dataIndex) {
if (data.highlight) {
angular.element( row ).addClass('highlight');
}
})
我正在使用 angularjs 数据表。如果某些条件为真,我想将自定义 class 添加到行中。 这是尝试过的方式:
this.dtOptions = DTOptionsBuilder.newOptions()
...
.withOption('createdRow', function (row, data, dataIndex) {
if (data.highlight) {
let el = angular.element( document.querySelector( 'tr:nth-child('+dataIndex+')' ) )
el.addClass('highlight');
}
})
...
data.highlight 对于某些行为真,因此条件正常,但 addClass 不起作用。
你不需要这么复杂的结构。由于您使用的是数据表,因此您确实有 jQuery 可用:
if (data.highlight) {
$( row ).addClass('highlight');
}
就足够了。
在 Angular 中你可以这样做。
.withOption('createdRow', function (row, data, dataIndex) {
if (data.highlight) {
angular.element( row ).addClass('highlight');
}
})