智能表 - 选择显示的第一行(angularjs)

标签 smart-table

使用智能表时是否可以自动选择第一行。我已经使用 ng-class 有条件地添加了 st-selected 类,该类突出显示了该行,但是当我选择另一行时,它不会取消选择第一行。

如果有任何帮助,我将不胜感激。

谢谢

最佳答案

我刚刚遇到了类似的问题,但想要有一个指定的默认选择,我通过分配咒骂和指令解决了这个问题。

(function(undefined) {
'use strict';

angular
    .module('mymodule')
    .directive('stDefaultSelection', function() {
    return {
        require: 'stTable',
        restrict: 'A',
        scope: {
            selection: '=stDefaultSelection',
        },
        link: function link(scope, element, attrs, controller) {
            scope.$watch('selection', function(newValue, oldValue) {
                var selectionMode = 'single';
                if (angular.isArray(newValue) && newValue.length > 1) {
                    selectionMode = 'multi';
                }
                if (angular.isArray(newValue)) {
                    newValue.forEach(function (row, index, array) {
                        controller.select(row, selectionMode);
                    });
                } else {
                    controller.select(newValue, selectionMode);
                }
            });
        }
    };
});
})();

然后在你的html中:

<table st-table="myCtrl.data.records" st-safe-src="myCtrl.data.safeRecords" st-default-selection="myCtrl.defaultRecord">

设置数据后,然后设置您的默认记录,这可能会解决您的问题。

关于智能表 - 选择显示的第一行(angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29193530/

相关文章:

javascript - 使用 angularJS 智能表

javascript - 将嵌套的 ng-repeat 与对象数组一起使用

javascript - 在智能表上禁用取消选择

html - 文本旁边的三 Angular 形

angularjs - 智能表格列显示/隐藏切换

angularjs - 智能表分页不适用于服务器端过滤

javascript - 如何在 Angular js 智能表中编辑内容

javascript - 带有 Angular 1.5.8 的智能表 - 行选择不起作用 - 范围未填写

javascript - AngularJS Smart Table 在显示所有行时用空格过滤特殊字符