负载pre-选择行具有角的UI网 [英] Pre-Select rows on load with angular-ui-grid

查看:141
本文介绍了负载pre-选择行具有角的UI网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要选择在页面加载某些行(工作日)

I want to select certain rows on page load(working days)

在这里输入的形象描述

这是plunker
  plnkr.co/edit/48NyxngWNGIlOps1Arew?p=$p$pview

任何建议?

推荐答案

下面的属性添加到 $ scope.gridOptions 对象:

Add the following property to your $scope.gridOptions object :

onRegisterApi: function(gridApi) {
    $scope.gridApi = gridApi;
    $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
    $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
}

此设置了一个 $ scope.gridApi 所以你可以,如果你需要这个功能之外访问它。

This sets a $scope.gridApi so you can access it if you need it outside of this function.

您需要调用 modifyRows 方法,以便能够更改您的行。

You need to call the modifyRows method in order to be able to make changes to your rows.

然后,第一行被选择(只是作为例子)。

Then the first row is selected (just as an example).

http://plnkr.co/edit/mvwlfaJiPDysbn2IrNpv?p=$p$ PVIEW

要选择工作日,也许你可以尝试的东西代替的最后一行是这样的:

To select the working days, maybe you can try replacing the last line by something like this :

$scope.gridOptions.data.forEach(function (row, index) {
    if (row.isWorkingDay()) {
        $scope.gridApi.selection.selectRow($scope.gridOptions.data[index]);
    }
});

row.isWorkingDay 可以简单地检查一天是给天的名单中。

row.isWorkingDay can simply check if the day is among a list of given days.

如果您的数据是由一个异步调用加载你可以简单的回调中选择行:

If your data is loaded by an async call you can simply select the rows in the callback :

asyncCall.then(function (data) {
    $scope.gridOptions.data = data;
    $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
    $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
});

这篇关于负载pre-选择行具有角的UI网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆