简体   繁体   English

Jhipster Filter仅适用于页面上的数据,而不适用于整个数据库

[英]Jhipster Filter only works on the data on the page, not the entire database

I need to add a filter to a Jhipster generated website. 我需要为Jhipster生成的网站添加一个过滤器。 The entity name is called "person", which has rec_no, firstName, lastName, gender and Dob. 实体名称称为“person”,它具有rec_no,firstName,lastName,gender和Dob。 I have around 2000 records in the database. 我在数据库中有大约2000条记录。 I added the filter in the person.html file, by adding: 我在person.html文件中添加了过滤器,添加:

<input type="text" placeholder="Rec No" ng-model="search.rec_no">
                  <input type="text" placeholder="First Name" ng-model="vm.searchFirstName">
                    <input type="text" placeholder="Last Name" ng-model="search.lastname">
                    <input type="text" placeholder="Gender" ng-model="search.sex">
                    <input type="text" placeholder="Dob" ng-model="search.dob">

And, 和,

 <tr ng-repeat="person in vm.people | filter:search track by person.id">

It works great, but the only problem is this filter only works for the data on the first page (or whatever page I am currently on). 它工作得很好,但唯一的问题是这个过滤器只适用于第一页上的数据(或我当前所在的任何页面)。 It won't search the entire database. 它不会搜索整个数据库。 I have never done anything in AngurlaJS or Jhipster, so I have totally no cure how to fix it. 我从未在AngurlaJS或Jhipster做过任何事情,所以我完全没有办法解决它的问题。 I guess I need to override the defualt pagination. 我想我需要覆盖defualt分页。 I did a lot research online, but can't find any help. 我在网上做了很多研究,但找不到任何帮助。 I hope anyone can help me out of this. 我希望任何人都可以帮助我。 Thank you. 谢谢。

Here is the full code, 这是完整的代码,

<div>
<h2 translate="archerApp.person.home.title">People</h2>
<jhi-alert></jhi-alert>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-4 no-padding-left">
            <button class="btn btn-primary" ui-sref="person.new" >
                <span class="glyphicon glyphicon-plus"></span>
                <span class="hidden-xs"  translate="archerApp.person.home.createLabel">
                    Create new Person
                </span>
            </button>
        </div>
        <div class="col-xs-8 no-padding-right">
            <form name="searchForm" class="form-inline">
                <div class="input-group pull-right" >
                    <input type="text" class="form-control" ng-model="vm.searchQuery" id="searchQuery" placeholder="{{ 'archerApp.person.home.search' | translate }}">
                    <span  class="input-group-btn width-min" >
                        <button class="btn btn-info" ng-click="vm.search(vm.searchQuery)">
                            <span class="glyphicon glyphicon-search"></span>
                        </button>
                    </span>
                    <span class="input-group-btn width-min" ng-if="vm.currentSearch">
                        <button class="btn btn-info" ng-click="vm.clear()">
                            <span class="glyphicon glyphicon-trash"></span>
                        </button>
                    </span>
                </div>
            </form>
        </div>
    </div>
</div>
<br/>
<div class="table-responsive">
    <table class="jh-table table table-striped">
        <thead>
            <tr jh-sort="vm.predicate" ascending="vm.reverse" callback="vm.transition()">
                <th jh-sort-by="rec_no"><span translate="archerApp.person.rec_no">Rec No</span> <span class="glyphicon glyphicon-sort"></span></th>
                <th jh-sort-by="firstname"><span translate="archerApp.person.firstname">Firstname</span> <span class="glyphicon glyphicon-sort"></span></th>                     
                <th jh-sort-by="maidenname"><span translate="archerApp.person.maidenname">Maidenname</span> <span class="glyphicon glyphicon-sort"></span></th>
                <th jh-sort-by="lastname"><span translate="archerApp.person.lastname">Lastname</span> <span class="glyphicon glyphicon-sort"></span></th>
                <th jh-sort-by="sex"><span translate="archerApp.person.sex">Sex</span> <span class="glyphicon glyphicon-sort"></span></th>
                <th jh-sort-by="dob"><span translate="archerApp.person.dob">Dob</span> <span class="glyphicon glyphicon-sort"></span></th>                    
                <th></th>
            </tr>
            <tr>
                  <input type="text" placeholder="Rec No" ng-model="search.rec_no">
                  <input type="text" placeholder="First Name" ng-model="vm.searchFirstName">
                    <input type="text" placeholder="Last Name" ng-model="search.lastname">
                    <input type="text" placeholder="Gender" ng-model="search.sex">
                    <input type="text" placeholder="Dob" ng-model="search.dob">
            </tr> 
        </thead>
        <tbody>
            <tr ng-repeat="person in vm.people | filter:search track by person.id">                    
                <td>{{person.rec_no}}</td>
                <td><a ui-sref="person-detail({id:person.id})">{{person.firstname}}</a></td>                    
                <td>{{person.maidenname}}</td>
                <td>{{person.lastname}}</td>
                <td translate="{{'archerApp.Gender.' + person.sex}}">{{person.sex}}</td>
                    <td>{{person.dob | date:'mediumDate'}}</td>                    
                <td class="text-right">
                    <div class="btn-group flex-btn-group-container">
                        <button type="submit"
                                ui-sref="person-detail({id:person.id})"
                                class="btn btn-info btn-sm">
                            <span class="glyphicon glyphicon-eye-open"></span>
                            <span class="hidden-xs hidden-sm" translate="entity.action.view"></span>
                        </button>
                        <button type="submit"
                                ui-sref="person.edit({id:person.id})"
                                class="btn btn-primary btn-sm">
                            <span class="glyphicon glyphicon-pencil"></span>
                            <span class="hidden-xs hidden-sm" translate="entity.action.edit"></span>
                        </button>
                        <button type="submit"
                                ui-sref="person.delete({id:person.id})"
                                class="btn btn-danger btn-sm">
                            <span class="glyphicon glyphicon-remove-circle"></span>
                            <span class="hidden-xs hidden-sm" translate="entity.action.delete"></span>
                        </button>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<div class="text-center">
    <jhi-item-count page="vm.page" total="vm.queryCount" items-per-page="vm.itemsPerPage"></jhi-item-count>
    <uib-pagination class="pagination-sm" total-items="vm.totalItems" ng-model="vm.page" ng-change="vm.transition()"></uib-pagination>
</div>

IMHO this is not solvable with just a few lines of code. 恕我直言,只用几行代码就无法解决这个问题。

When talking about filtering in general, there is local and remote filtering. 在谈到一般的过滤时,有本地远程过滤。 Local means, you got your full data already in memory and filter that data. 本地意味着,您已将完整数据存储在内存中并过滤该数据。 When using Angular, this is very much comfortable, as your search string is compared to every attribute stored in memory, which gives a pretty good search. 使用Angular时,这非常舒服,因为您的搜索字符串与存储在内存中的每个属性进行比较,这提供了相当不错的搜索。 However, this approachs works only on the current page and only for a few data sets. 但是,此方法仅适用于当前页面,仅适用于少数数据集。 If you got more data sets, and?or want to filter your database by specific terms, you must filter server side . 如果您有更多数据集,并且?或者想要按特定术语过滤数据库,则必须过滤服务器端 This means typing in the searchbar performs XHTTP request to your JHipster backend, so the data in your browsers memory is already filtered when responded. 这意味着键入搜索栏会对JHipster后端执行XHTTP请求,因此浏览器内存中的数据在响应时已经过滤。

There is more than one way to solve it. 解决它的方法不止一种。 You either can implement custom search logic inside JPA repositories, or enable elasticsearch for indexing your structured data into a search Database. 您可以在JPA存储库中实现自定义搜索逻辑,也可以启用elasticsearch将结构化数据索引到搜索数据库中。 This approach gives you more power to design your filter logic, but is also more difficult. 这种方法为您提供了设计滤波器逻辑的更多功能,但也更加困难。

I suggest to check the official JHipster documentation to get a better picture of the options. 我建议查看官方的JHipster文档 ,以更好地了解选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM