简体   繁体   English

默认情况下,焦点在过滤器标题ui网格中

[英]Focus by default in filter header angular ui grid

I have gone through the documentation forward and back and I cannot seem to find a way to give the header filter for one of the columns focus when it loads. 我已经遍历了文档,似乎无法找到一种在加载时为其中一个列焦点提供标题过滤器的方法。 The user typically filters on the same column every single time. 用户通常每次都在同一列上进行过滤。 I use these grids for line of business applications and every click or 'tab' saved is 500 saved per person per day. 我将这些网格用于业务应用程序,每点击或保存的“选项卡”每人每天节省500。

this.gridOptions.columnDefs = [
            { field: 'Order' },
            { field: 'Qty.' }
        ];

Then I have the following for the html, so Order gets a filter, but it is not focused by default. 然后,我为html提供了以下内容,因此Order获得了一个过滤器,但默认情况下未聚焦。

<div ui-grid="taskCtrl.gridOptions" ui-grid-selection ui-grid-auto-resize></div>

Thanks! 谢谢!

Here is a solution I found out for this problem. 这是我针对此问题找到的解决方案。

You need to add autofocus to text box of the header filter while creating the column definition. 创建列定义时,需要在标题过滤器的文本框中添加自动对焦。 You can do this by coding something like this: 您可以通过编码如下代码来做到这一点:

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
  { field: 'name' },
  { field: 'company',
    headerCellTemplate: '<div ng-class="{ \'sortable\': sortable }"><div class="ui-grid-vertical-bar">&nbsp;</div><div class="ui-grid-cell-contents" col-index="renderIndex"><span>{{ col.displayName CUSTOM_FILTERS }}</span><span ui-grid-visible="col.sort.direction" ng-class="{ \'ui-grid-icon-up-dir\': col.sort.direction == asc, \'ui-grid-icon-down-dir\': col.sort.direction == desc, \'ui-grid-icon-blank\': !col.sort.direction }">&nbsp;</span></div><div class="ui-grid-column-menu-button" ng-if="grid.options.enableColumnMenus && !col.isRowHeader  && col.colDef.enableColumnMenu !== false" class="ui-grid-column-menu-button" ng-click="toggleMenu($event)"><i class="ui-grid-icon-angle-down">&nbsp;</i></div><div ng-if="filterable" class="ui-grid-filter-container" ng-repeat="colFilter in col.filters"><input type="text" autofocus class="ui-grid-filter-input" ng-model="colFilter.term" ng-click="$event.stopPropagation()" ng-attr-placeholder="{{colFilter.placeholder || \'\'}}" /><div class="ui-grid-filter-button" ng-click="colFilter.term = null"><i class="ui-grid-icon-cancel" ng-show="!!colFilter.term">&nbsp;</i> <!-- use !! because angular interprets \'f\' as false --></div></div></div>'
  }
],
onRegisterApi: function( gridApi ) {
  $scope.gridApi = gridApi;
  $scope.gridApi.core.on.sortChanged( $scope, function( grid, sort ) {
    $scope.gridApi.core.notifyDataChange( $scope.gridApi.grid, uiGridConstants.dataChange.COLUMN );
  })
}

}; };

In the above code sample you can see that the headerCellTemplate is being written explicitly. 在上面的代码示例中,您可以看到headerCellTemplate正在显式编写。 Here is the place you can do the change to get the autofocus. 在这里您可以进行更改以获得自动对焦。 You can do anything you want in this cell template. 您可以在此单元格模板中执行任何所需的操作。 But be careful not to change any underlying cell template. 但是请注意不要更改任何底层单元格模板。 This may break ui-grid functionality. 这可能会破坏ui-grid功能。 Hope this helps! 希望这可以帮助!

I found the above solution in the below plunker link: http://plnkr.co/edit/JuDUwpUBwglkDRUYT77g?p=preview 我在下面的链接链接中找到了上述解决方案: http ://plnkr.co/edit/JuDUwpUBwglkDRUYT77g?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM