Can I change the default mat-paginator size depending on screensize?










2















I have a angular project with a mat-table and a mat-paginator, similar to the following:



<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
<td mat-cell *matCellDef="let row"> row.id </td>
</ng-container>
<ng-container matColumnDef="progress">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
<td mat-cell *matCellDef="let row"> row.progress% </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> row.name </td>
</ng-container>
<ng-container matColumnDef="color">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
<td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;">
</tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
</div>


Also available here: Stackblitz Example



As you can see the pageSizeOptions are set to [5, 10, 15, 20, 25, dataSource.data.length]



I would like to be able to set the first value in this array (the default value) to be different depending on the screensize. So on smaller screens I'd have 10 as the default value, and larger screens I'd have 15.



Is this even a good idea/practice to do this?










share|improve this question


























    2















    I have a angular project with a mat-table and a mat-paginator, similar to the following:



    <div class="mat-elevation-z8">
    <table mat-table [dataSource]="dataSource" matSort>
    <ng-container matColumnDef="id">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
    <td mat-cell *matCellDef="let row"> row.id </td>
    </ng-container>
    <ng-container matColumnDef="progress">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
    <td mat-cell *matCellDef="let row"> row.progress% </td>
    </ng-container>
    <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
    <td mat-cell *matCellDef="let row"> row.name </td>
    </ng-container>
    <ng-container matColumnDef="color">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
    <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;">
    </tr>
    </table>
    <mat-paginator [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
    </div>


    Also available here: Stackblitz Example



    As you can see the pageSizeOptions are set to [5, 10, 15, 20, 25, dataSource.data.length]



    I would like to be able to set the first value in this array (the default value) to be different depending on the screensize. So on smaller screens I'd have 10 as the default value, and larger screens I'd have 15.



    Is this even a good idea/practice to do this?










    share|improve this question
























      2












      2








      2








      I have a angular project with a mat-table and a mat-paginator, similar to the following:



      <div class="mat-elevation-z8">
      <table mat-table [dataSource]="dataSource" matSort>
      <ng-container matColumnDef="id">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
      <td mat-cell *matCellDef="let row"> row.id </td>
      </ng-container>
      <ng-container matColumnDef="progress">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
      <td mat-cell *matCellDef="let row"> row.progress% </td>
      </ng-container>
      <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
      <td mat-cell *matCellDef="let row"> row.name </td>
      </ng-container>
      <ng-container matColumnDef="color">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
      <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
      </ng-container>

      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: displayedColumns;">
      </tr>
      </table>
      <mat-paginator [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
      </div>


      Also available here: Stackblitz Example



      As you can see the pageSizeOptions are set to [5, 10, 15, 20, 25, dataSource.data.length]



      I would like to be able to set the first value in this array (the default value) to be different depending on the screensize. So on smaller screens I'd have 10 as the default value, and larger screens I'd have 15.



      Is this even a good idea/practice to do this?










      share|improve this question














      I have a angular project with a mat-table and a mat-paginator, similar to the following:



      <div class="mat-elevation-z8">
      <table mat-table [dataSource]="dataSource" matSort>
      <ng-container matColumnDef="id">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
      <td mat-cell *matCellDef="let row"> row.id </td>
      </ng-container>
      <ng-container matColumnDef="progress">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
      <td mat-cell *matCellDef="let row"> row.progress% </td>
      </ng-container>
      <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
      <td mat-cell *matCellDef="let row"> row.name </td>
      </ng-container>
      <ng-container matColumnDef="color">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
      <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
      </ng-container>

      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: displayedColumns;">
      </tr>
      </table>
      <mat-paginator [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
      </div>


      Also available here: Stackblitz Example



      As you can see the pageSizeOptions are set to [5, 10, 15, 20, 25, dataSource.data.length]



      I would like to be able to set the first value in this array (the default value) to be different depending on the screensize. So on smaller screens I'd have 10 as the default value, and larger screens I'd have 15.



      Is this even a good idea/practice to do this?







      angular angular7 paginator






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 4:46









      WoodyWoody

      3161614




      3161614






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You can use onresize event : (window:resize)="onResize($event)"



          <div class="mat-elevation-z8" (window:resize)="onResize($event)">
          <table mat-table [dataSource]="dataSource" matSort>

          <!-- ID Column -->
          <ng-container matColumnDef="id">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
          <td mat-cell *matCellDef="let row"> row.id </td>
          </ng-container>

          <!-- Progress Column -->
          <ng-container matColumnDef="progress">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
          <td mat-cell *matCellDef="let row"> row.progress% </td>
          </ng-container>

          <!-- Name Column -->
          <ng-container matColumnDef="name">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
          <td mat-cell *matCellDef="let row"> row.name </td>
          </ng-container>

          <!-- Color Column -->
          <ng-container matColumnDef="color">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
          <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
          </ng-container>

          <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: displayedColumns;">
          </tr>
          </table>

          <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
          </div>


          //your component



           onResize(event) 

          console.log(event.target.innerWidth);
          if (event.target.innerWidth > 600 && event.target.innerWidth < 800)
          this.pageSize = 10;

          else if (event.target.innerWidth > 800 && event.target.innerWidth < 1000)
          this.pageSize = 15;
          else
          this.pageSize = 5;





          Default page size should be 5



          pageSize = 5;


          You can check demo here and bind it according to your requirement of screen.






          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%2f53273972%2fcan-i-change-the-default-mat-paginator-size-depending-on-screensize%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









            2














            You can use onresize event : (window:resize)="onResize($event)"



            <div class="mat-elevation-z8" (window:resize)="onResize($event)">
            <table mat-table [dataSource]="dataSource" matSort>

            <!-- ID Column -->
            <ng-container matColumnDef="id">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
            <td mat-cell *matCellDef="let row"> row.id </td>
            </ng-container>

            <!-- Progress Column -->
            <ng-container matColumnDef="progress">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
            <td mat-cell *matCellDef="let row"> row.progress% </td>
            </ng-container>

            <!-- Name Column -->
            <ng-container matColumnDef="name">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
            <td mat-cell *matCellDef="let row"> row.name </td>
            </ng-container>

            <!-- Color Column -->
            <ng-container matColumnDef="color">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
            <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
            </ng-container>

            <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: displayedColumns;">
            </tr>
            </table>

            <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
            </div>


            //your component



             onResize(event) 

            console.log(event.target.innerWidth);
            if (event.target.innerWidth > 600 && event.target.innerWidth < 800)
            this.pageSize = 10;

            else if (event.target.innerWidth > 800 && event.target.innerWidth < 1000)
            this.pageSize = 15;
            else
            this.pageSize = 5;





            Default page size should be 5



            pageSize = 5;


            You can check demo here and bind it according to your requirement of screen.






            share|improve this answer





























              2














              You can use onresize event : (window:resize)="onResize($event)"



              <div class="mat-elevation-z8" (window:resize)="onResize($event)">
              <table mat-table [dataSource]="dataSource" matSort>

              <!-- ID Column -->
              <ng-container matColumnDef="id">
              <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
              <td mat-cell *matCellDef="let row"> row.id </td>
              </ng-container>

              <!-- Progress Column -->
              <ng-container matColumnDef="progress">
              <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
              <td mat-cell *matCellDef="let row"> row.progress% </td>
              </ng-container>

              <!-- Name Column -->
              <ng-container matColumnDef="name">
              <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
              <td mat-cell *matCellDef="let row"> row.name </td>
              </ng-container>

              <!-- Color Column -->
              <ng-container matColumnDef="color">
              <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
              <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
              </ng-container>

              <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
              <tr mat-row *matRowDef="let row; columns: displayedColumns;">
              </tr>
              </table>

              <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
              </div>


              //your component



               onResize(event) 

              console.log(event.target.innerWidth);
              if (event.target.innerWidth > 600 && event.target.innerWidth < 800)
              this.pageSize = 10;

              else if (event.target.innerWidth > 800 && event.target.innerWidth < 1000)
              this.pageSize = 15;
              else
              this.pageSize = 5;





              Default page size should be 5



              pageSize = 5;


              You can check demo here and bind it according to your requirement of screen.






              share|improve this answer



























                2












                2








                2







                You can use onresize event : (window:resize)="onResize($event)"



                <div class="mat-elevation-z8" (window:resize)="onResize($event)">
                <table mat-table [dataSource]="dataSource" matSort>

                <!-- ID Column -->
                <ng-container matColumnDef="id">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
                <td mat-cell *matCellDef="let row"> row.id </td>
                </ng-container>

                <!-- Progress Column -->
                <ng-container matColumnDef="progress">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
                <td mat-cell *matCellDef="let row"> row.progress% </td>
                </ng-container>

                <!-- Name Column -->
                <ng-container matColumnDef="name">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
                <td mat-cell *matCellDef="let row"> row.name </td>
                </ng-container>

                <!-- Color Column -->
                <ng-container matColumnDef="color">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
                <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
                </ng-container>

                <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                <tr mat-row *matRowDef="let row; columns: displayedColumns;">
                </tr>
                </table>

                <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
                </div>


                //your component



                 onResize(event) 

                console.log(event.target.innerWidth);
                if (event.target.innerWidth > 600 && event.target.innerWidth < 800)
                this.pageSize = 10;

                else if (event.target.innerWidth > 800 && event.target.innerWidth < 1000)
                this.pageSize = 15;
                else
                this.pageSize = 5;





                Default page size should be 5



                pageSize = 5;


                You can check demo here and bind it according to your requirement of screen.






                share|improve this answer















                You can use onresize event : (window:resize)="onResize($event)"



                <div class="mat-elevation-z8" (window:resize)="onResize($event)">
                <table mat-table [dataSource]="dataSource" matSort>

                <!-- ID Column -->
                <ng-container matColumnDef="id">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
                <td mat-cell *matCellDef="let row"> row.id </td>
                </ng-container>

                <!-- Progress Column -->
                <ng-container matColumnDef="progress">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
                <td mat-cell *matCellDef="let row"> row.progress% </td>
                </ng-container>

                <!-- Name Column -->
                <ng-container matColumnDef="name">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
                <td mat-cell *matCellDef="let row"> row.name </td>
                </ng-container>

                <!-- Color Column -->
                <ng-container matColumnDef="color">
                <th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
                <td mat-cell *matCellDef="let row" [style.color]="row.color"> row.color </td>
                </ng-container>

                <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                <tr mat-row *matRowDef="let row; columns: displayedColumns;">
                </tr>
                </table>

                <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 15, 20, 25, dataSource.data.length]"></mat-paginator>
                </div>


                //your component



                 onResize(event) 

                console.log(event.target.innerWidth);
                if (event.target.innerWidth > 600 && event.target.innerWidth < 800)
                this.pageSize = 10;

                else if (event.target.innerWidth > 800 && event.target.innerWidth < 1000)
                this.pageSize = 15;
                else
                this.pageSize = 5;





                Default page size should be 5



                pageSize = 5;


                You can check demo here and bind it according to your requirement of screen.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 13 '18 at 5:09

























                answered Nov 13 '18 at 5:04









                Just codeJust code

                9,90252966




                9,90252966



























                    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%2f53273972%2fcan-i-change-the-default-mat-paginator-size-depending-on-screensize%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







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3