通过输入值/值范围来进行明确的过滤

时间:2015-03-10 04:36:33

标签: angularjs ngtable

我是Angularjs的新手,并且使用了ngtable内置过滤器,但它仅在按键时过滤。 我有2个搜索选项: 1)根据在文本框中输入的值过滤数据。 2)根据两个文本框(from,to)中的值范围过滤数据。

点击按钮即可进行过滤。 用户可以在上述3个文本框中的任何一个中输入值,然后单击“提交”以使过滤器发生。

我的HTML代码:

    Enter Article Name to search:<input type="text" name="articlename">
    Article number from:<input type="text" name="articlenumfrom">
    Article number to:<input type="text" name="articlenumto">
    <input type="submit" value="Submit" ng-click="doSearch()">

我的控制器代码:

    var app = angular.module('main', ['ngTable']).
    controller('DemoCtrl', function($scope, ngTableParams) {
    var data = [{articlename: "coffee", articleid: 50}
    {articlename: "tea", articleid: 43},
    {articlename: "biscuit", articleid: 27},
    {articlename: "sugar", articleid: 29},
    {articlename: "salt", articleid: 34},
    {articlename: "apple", articleid: 43},
    {articlename: "banana", articleid: 27},
    {articlename: "orange", articleid: 34}];
    $scope.tableParams = new ngTableParams({
    particleid: 1,            // show first page
    count: 10           // count per page
    }, {
    total: data.length, // length of data
    getData: function($defer, params) {
    $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
    });
    });

0 个答案:

没有答案