如何使用单个文本框根据任何列数据过滤行 [英] How do i filter a row based on any column data with single textbox

查看:28
本文介绍了如何使用单个文本框根据任何列数据过滤行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ng-table.

I am using ng-table.

我尝试使用 example 中给出的过滤器,但是为了过滤每个列我需要有单独的文本框.

I tried to use filter given in the example, but for filtering each column i need to have separate textbox.

但我要实现的是,一个文本框可以根据任何列数据搜索任何行.

But what i tying to achieve is, One textbox to search any row based on any column data.

我怎样才能做到这一点?

How can i achieve this ?

就像jquery datatable 搜索框一样.

推荐答案

我就是这样做的

HTML

    <input type="text" ng-model="searchUser">

    <table ng-table="tableParams">
      <tr ng-repeat="user in $data">
        ...
      </tr>
    </table>

脚本

        var usersData = []; // initial data

        $scope.tableParams = new ngTableParams({
            page: 1,           
            count: 7
        }, {
        counts : [7,14,21,28],          
        getData: function($defer, params) {
            var searchedData = searchData();
            params.total(searchedData.length);
            $scope.users = searchedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
            $defer.resolve($scope.users);                           
        },
        $scope: { $data: {} }
    });


$scope.$watch("searchUser", function () {
    $scope.tableParams.reload();
});

var searchData = function(){
    if($scope.searchUser)
       return $filter('filter')(usersData,$scope.searchUser);
    return usersData;
}

剩余默认ngtable配置.

这篇关于如何使用单个文本框根据任何列数据过滤行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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