angular-ui / ui-grid

UI Grid: an Angular Data Grid
http://ui-grid.info
MIT License
5.39k stars 2.47k forks source link

Show relevant data in the table #6991

Closed Gikus closed 5 years ago

Gikus commented 5 years ago

Hello! I have a similar code and I think it renders matched data within the table. I'm not savvy in programming and may be you could make some tweaks here. I need it to show any entered data if such exists in the address list and not only exact match with all the uppercase and lowercase, commas and so on. Now it displays only exact match. The address list and the search bar: http://wp3.it-do.pw72n.spectrum.myjino.ru/sample-page/

My code:

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()"/>

Originally posted by @Gikus in https://github.com/angular-ui/ui-grid/issues/4224#issuecomment-494731725

ridespirals commented 5 years ago
var matcher = new RegExp($scope.filterValue);

You're creating a regular expression based on the text. Just set the i flag for case-insensitivity. For instance:

var matcher = new RegExp($scope.filterValue, 'i');

This won't help ignore punctuation, but since you're using a regex`, then you'll just need to customize the regular expression.

You could also use $scope.filterValue to do a manual string comparison, instead of deferring entirely to regex.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically closed because it has not had recent activity. If you believe that this is still an issue in the latest version, feel free to re-open it. Thank you for your contributions.