无论格式如何显示任何匹配的数据

时间:2019-05-16 10:47:38

标签: javascript angularjs angularjs-filter ui-grid

可能是我错了,但是我认为这段代码仅在与地址完全匹配时才查找和显示数据,并使用所有大小写,逗号等。如何更改它以使其显示任何匹配的地址,而不管格式如何?涉及json和csv文件。我的页面:http://wp3.it-do.pw72n.spectrum.myjino.ru/sample-page/。带有应用程序教程的网站:http://ui-grid.info/docs/#!/tutorial/Tutorial:%20306%20Custom%20Filters。在第一个选项“名称”下,您可以在其中输入文本的输入中找到该名称,它将显示所有匹配项,无论大小写,我都希望相同。这里也是一个示例,它如何工作:https://docs.angularjs.org/api/ng/filter/filter


var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pagination']);
app.controller('MainCtrl', ['i18nService', function(i18nService){
    //es is the language prefix you want
    i18nService.setCurrentLang('ru');
}]);

app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
    $scope.getTableHeight = function() {
        var rowHeight = 30; // your row height
        var headerHeight = 30; // your header height
        return {
            height: (25 * rowHeight + headerHeight-20) + "px"
        };
    };


    $scope.gridOptions1 = {
        rowHeight: 30,
        enableFiltering: false,
        onRegisterApi: function(gridApi){
            $scope.gridApi = gridApi;
            $scope.gridApi.grid.registerRowsProcessor( $scope.singleFilter, 200 );
        },
        paginationPageSizes: [25,50,100,250,1000],
        paginationPageSize: 25,
        columnDefs: [
            { name: 'adress',displayName: 'Адрес', enableColumnMenu: false},
            { name: 'dolg', displayName: 'Задолженность, руб', enableColumnMenu: false,width: '25%'
            },
            { name: 'oplata', displayName: 'Оплатить', enableColumnMenu: false, cellTemplate: '<a class="ui-grid-cell-contents right_color" href="/oplata-step2/?{{\'address=\'+row.entity.adress+\'&summa=\'+ row.entity.dolg}}">Оплатить</a>',width: '20%' }

        ]

    };


$http.get('/moduleOplata/data.php')
        .then(function (response) {
            $scope.gridOptions1.data = response.data;
        });

    $scope.filter = function() {
        $scope.gridApi.grid.refresh();
    };

    $scope.singleFilter = function( renderableRows ){
        var matcher = new RegExp($scope.filterValue);
        renderableRows.forEach( function( row ) {
            var match = false;
            [ 'adress'].forEach(function( field ){
                if ( row.entity[field].match(matcher) ){
                    match = true;
                }
            });
            if ( !match ){
                row.visible = false;
            }
        });
        return renderableRows;
    };
<input ng-model='filterValue' class="search_block" placeholder="Введите адрес для поиска" ng-change="filter()"/>
<div ui-grid="gridOptions1" ui-grid-pagination class="grid" ng-style="getTableHeight()"></div>

0 个答案:

没有答案