网格中的Ng网格搜索栏

时间:2014-10-10 17:41:41

标签: angularjs ng-grid

现在我正在使用ng-grid和网格选项showFilter: true

这会在网格的右上角放置一个三角形下拉菜单,点击后会弹出一个搜索栏。

有没有办法让ng-grid让搜索栏在网格中直接可见,而无需点击三角形?

1 个答案:

答案 0 :(得分:0)

当然,只需使用ng-grid在视图中的任何位置输入文本:

<input type="text" data-ng-model="outside_search_text" placeholder="Search"
                                       class="form-control" data-ng-change="search()">
<div class="gridStyle" data-ng-grid="gridOptions">
                        </div>

然后在你的控制器中:

$scope.sortOptions = {
        fields      : ['id'],
        directions  : ['DESC']
    };


    $scope.totalServerItems         = 0;
    $scope.gridOptions['sortInfo']  = $scope.sortOptions;

    $scope.gridOptions['columnDefs'] = [
        {field          : 'name', displayName: 'Name'}
    ];


    $scope.refresh = function() {
        var p = {
            searchText      : {name: $scope.outside_search_text},
            pageNumber      : $scope.pagingOptions.currentPage,
            pageSize        : $scope.pagingOptions.pageSize,
            sortField       : $scope.sortOptions.fields,
            sortDirection   : $scope.sortOptions.directions
        };

        YourServices.getAll(p).then(function(response) {
            var content = getResponseData(response);

            $scope.totalServerItems = content.count;
            $scope.myData           = content.result_set;

            if (content['result_set'].length > 0) {
                //whatever
            } else {
                //whatever
            }
        });
    };