angular 4 filter pipe used with server pagination





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am using filter with pagination. It works fine but the problem is that when i search Name it filters the result but pagination remains the same like if search result return 3 filter records the pagination stills shows pages and user can navigate these pages. I want to change my pagination number with search filter. Here is my example code



    <input type="text" placeholder="User Name" name="username" [(ngModel)]="_userListParams.UserName" class="form-control">

<pagination-controls (pageChange)="pageChanged($event)" (pageChange)="Paging.currentPage = $event"></pagination-controls>

<table class="table table-hover">
<thead>
<tr>
<th *ngFor="let cell of tableData2.headerRow">{{ cell }}</th>
</tr>
</thead>
<tbody>
<tr [routerLink]="['/UserDetails', row.Id]" *ngFor="let row of tableData2.dataRows | filter: 'Name': _userListParams.UserName | paginate: { itemsPerPage: Paging.pageSize, currentPage: Paging.currentPage,totalItems: Paging.totalCount} ;let i = index;">
<td>{{i+1}}</td>
<td>{{row.Name}}</td>
<td>{{row.TypeName}}</td>
<td>{{row.Country}}</td>
<td>{{row.Status}}</td>
<td>{{row.ItemsQty}}</td>
<td><img class="panel-profile-img" height="70" width="70" src="{{imgurl+row.ProfilePic}}" alt=""></td>
</tr>
<tr *ngIf="tableData2.dataRows.length == 0">
<td colspan="7" class="text-center text-danger">No Record Found!</td>
</tr>
</tbody>
</table>


Here is my pipe i am using



@Pipe({ name: "filter" })
export class FilterPipe implements PipeTransform {
transform(items: any,field: string, searchText: string): any {
if(!items) return ;
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
debugger;
return it[field].toLowerCase().includes(searchText);
});
}
}


Attached Image



enter image description here










share|improve this question

























  • you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

    – enno.void
    Jan 3 at 13:08











  • yes i have to use multiple pipes to achieve my goal.

    – Shamshad Jamal
    Jan 3 at 13:13











  • You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

    – Alexander Staroselsky
    Jan 3 at 13:45


















0















I am using filter with pagination. It works fine but the problem is that when i search Name it filters the result but pagination remains the same like if search result return 3 filter records the pagination stills shows pages and user can navigate these pages. I want to change my pagination number with search filter. Here is my example code



    <input type="text" placeholder="User Name" name="username" [(ngModel)]="_userListParams.UserName" class="form-control">

<pagination-controls (pageChange)="pageChanged($event)" (pageChange)="Paging.currentPage = $event"></pagination-controls>

<table class="table table-hover">
<thead>
<tr>
<th *ngFor="let cell of tableData2.headerRow">{{ cell }}</th>
</tr>
</thead>
<tbody>
<tr [routerLink]="['/UserDetails', row.Id]" *ngFor="let row of tableData2.dataRows | filter: 'Name': _userListParams.UserName | paginate: { itemsPerPage: Paging.pageSize, currentPage: Paging.currentPage,totalItems: Paging.totalCount} ;let i = index;">
<td>{{i+1}}</td>
<td>{{row.Name}}</td>
<td>{{row.TypeName}}</td>
<td>{{row.Country}}</td>
<td>{{row.Status}}</td>
<td>{{row.ItemsQty}}</td>
<td><img class="panel-profile-img" height="70" width="70" src="{{imgurl+row.ProfilePic}}" alt=""></td>
</tr>
<tr *ngIf="tableData2.dataRows.length == 0">
<td colspan="7" class="text-center text-danger">No Record Found!</td>
</tr>
</tbody>
</table>


Here is my pipe i am using



@Pipe({ name: "filter" })
export class FilterPipe implements PipeTransform {
transform(items: any,field: string, searchText: string): any {
if(!items) return ;
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
debugger;
return it[field].toLowerCase().includes(searchText);
});
}
}


Attached Image



enter image description here










share|improve this question

























  • you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

    – enno.void
    Jan 3 at 13:08











  • yes i have to use multiple pipes to achieve my goal.

    – Shamshad Jamal
    Jan 3 at 13:13











  • You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

    – Alexander Staroselsky
    Jan 3 at 13:45














0












0








0








I am using filter with pagination. It works fine but the problem is that when i search Name it filters the result but pagination remains the same like if search result return 3 filter records the pagination stills shows pages and user can navigate these pages. I want to change my pagination number with search filter. Here is my example code



    <input type="text" placeholder="User Name" name="username" [(ngModel)]="_userListParams.UserName" class="form-control">

<pagination-controls (pageChange)="pageChanged($event)" (pageChange)="Paging.currentPage = $event"></pagination-controls>

<table class="table table-hover">
<thead>
<tr>
<th *ngFor="let cell of tableData2.headerRow">{{ cell }}</th>
</tr>
</thead>
<tbody>
<tr [routerLink]="['/UserDetails', row.Id]" *ngFor="let row of tableData2.dataRows | filter: 'Name': _userListParams.UserName | paginate: { itemsPerPage: Paging.pageSize, currentPage: Paging.currentPage,totalItems: Paging.totalCount} ;let i = index;">
<td>{{i+1}}</td>
<td>{{row.Name}}</td>
<td>{{row.TypeName}}</td>
<td>{{row.Country}}</td>
<td>{{row.Status}}</td>
<td>{{row.ItemsQty}}</td>
<td><img class="panel-profile-img" height="70" width="70" src="{{imgurl+row.ProfilePic}}" alt=""></td>
</tr>
<tr *ngIf="tableData2.dataRows.length == 0">
<td colspan="7" class="text-center text-danger">No Record Found!</td>
</tr>
</tbody>
</table>


Here is my pipe i am using



@Pipe({ name: "filter" })
export class FilterPipe implements PipeTransform {
transform(items: any,field: string, searchText: string): any {
if(!items) return ;
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
debugger;
return it[field].toLowerCase().includes(searchText);
});
}
}


Attached Image



enter image description here










share|improve this question
















I am using filter with pagination. It works fine but the problem is that when i search Name it filters the result but pagination remains the same like if search result return 3 filter records the pagination stills shows pages and user can navigate these pages. I want to change my pagination number with search filter. Here is my example code



    <input type="text" placeholder="User Name" name="username" [(ngModel)]="_userListParams.UserName" class="form-control">

<pagination-controls (pageChange)="pageChanged($event)" (pageChange)="Paging.currentPage = $event"></pagination-controls>

<table class="table table-hover">
<thead>
<tr>
<th *ngFor="let cell of tableData2.headerRow">{{ cell }}</th>
</tr>
</thead>
<tbody>
<tr [routerLink]="['/UserDetails', row.Id]" *ngFor="let row of tableData2.dataRows | filter: 'Name': _userListParams.UserName | paginate: { itemsPerPage: Paging.pageSize, currentPage: Paging.currentPage,totalItems: Paging.totalCount} ;let i = index;">
<td>{{i+1}}</td>
<td>{{row.Name}}</td>
<td>{{row.TypeName}}</td>
<td>{{row.Country}}</td>
<td>{{row.Status}}</td>
<td>{{row.ItemsQty}}</td>
<td><img class="panel-profile-img" height="70" width="70" src="{{imgurl+row.ProfilePic}}" alt=""></td>
</tr>
<tr *ngIf="tableData2.dataRows.length == 0">
<td colspan="7" class="text-center text-danger">No Record Found!</td>
</tr>
</tbody>
</table>


Here is my pipe i am using



@Pipe({ name: "filter" })
export class FilterPipe implements PipeTransform {
transform(items: any,field: string, searchText: string): any {
if(!items) return ;
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
debugger;
return it[field].toLowerCase().includes(searchText);
});
}
}


Attached Image



enter image description here







angular pagination angular-pipe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 13:16







Shamshad Jamal

















asked Jan 3 at 13:03









Shamshad JamalShamshad Jamal

719




719













  • you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

    – enno.void
    Jan 3 at 13:08











  • yes i have to use multiple pipes to achieve my goal.

    – Shamshad Jamal
    Jan 3 at 13:13











  • You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

    – Alexander Staroselsky
    Jan 3 at 13:45



















  • you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

    – enno.void
    Jan 3 at 13:08











  • yes i have to use multiple pipes to achieve my goal.

    – Shamshad Jamal
    Jan 3 at 13:13











  • You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

    – Alexander Staroselsky
    Jan 3 at 13:45

















you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

– enno.void
Jan 3 at 13:08





you are using multiple pipes, i think the "paginate" pipe is more interesting for your question

– enno.void
Jan 3 at 13:08













yes i have to use multiple pipes to achieve my goal.

– Shamshad Jamal
Jan 3 at 13:13





yes i have to use multiple pipes to achieve my goal.

– Shamshad Jamal
Jan 3 at 13:13













You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

– Alexander Staroselsky
Jan 3 at 13:45





You should really avoid using a pipe for filtering, instead just filter in the component using array methods or RxJS.

– Alexander Staroselsky
Jan 3 at 13:45












1 Answer
1






active

oldest

votes


















0














Try setting the autoHide option on the <pagination-controls> element to force it to disappear if all results fit onto page 1.



Documentation linked to the relevant section: https://www.npmjs.com/package/ngx-pagination#api



Edited to remove my suggestion to remove the totalItems option. Missed the part of the title where you said "server pagination". Facepalm.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022873%2fangular-4-filter-pipe-used-with-server-pagination%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try setting the autoHide option on the <pagination-controls> element to force it to disappear if all results fit onto page 1.



    Documentation linked to the relevant section: https://www.npmjs.com/package/ngx-pagination#api



    Edited to remove my suggestion to remove the totalItems option. Missed the part of the title where you said "server pagination". Facepalm.






    share|improve this answer






























      0














      Try setting the autoHide option on the <pagination-controls> element to force it to disappear if all results fit onto page 1.



      Documentation linked to the relevant section: https://www.npmjs.com/package/ngx-pagination#api



      Edited to remove my suggestion to remove the totalItems option. Missed the part of the title where you said "server pagination". Facepalm.






      share|improve this answer




























        0












        0








        0







        Try setting the autoHide option on the <pagination-controls> element to force it to disappear if all results fit onto page 1.



        Documentation linked to the relevant section: https://www.npmjs.com/package/ngx-pagination#api



        Edited to remove my suggestion to remove the totalItems option. Missed the part of the title where you said "server pagination". Facepalm.






        share|improve this answer















        Try setting the autoHide option on the <pagination-controls> element to force it to disappear if all results fit onto page 1.



        Documentation linked to the relevant section: https://www.npmjs.com/package/ngx-pagination#api



        Edited to remove my suggestion to remove the totalItems option. Missed the part of the title where you said "server pagination". Facepalm.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 3 at 16:12

























        answered Jan 3 at 15:37









        christine.hackchristine.hack

        12




        12
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022873%2fangular-4-filter-pipe-used-with-server-pagination%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory