Changing the Options for Page Size in Material Paginator

Firstly, here is my angular code:

ts:

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit, AfterViewInit{

  dataSource = new MatTableDataSource<Ticket>();
  ticketList: Ticket[] = [];
  originalTicketList: Ticket[] = [];
  displayedColumns = ['id', 'findingSourceSystem', 'label', 'caseStatus', 'caseCreateTimestamp', 'resolvedBy', 'resolution', 'resolutionNote'];
  filterAllForm: FormGroup;

  maxall : number = 100;


  @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  @ViewChild(MatSort, { static: false }) sort: MatSort;

  constructor(private ticket: TicketService,
    private formBuilder: FormBuilder) { }

  ngOnInit() {
    this.filterAllForm = this.formBuilder.group({
      startDate: [''],
      endDate: ['']
    });
    this.getAllLabels();
    this.getAllTicket();
    this.getAllUniqueLabels();

  }

  ngAfterViewInit(){
    this.dataSource.sort =  this.sort;
    this.dataSource.paginator = this.paginator;
    this.getPageSizeOptions();

  }
  getPageSizeOptions(): number[] {
    if (this.dataSource.data.length>this.maxall){
      return [20, 50, this.dataSource.data.length];
    }else{
      return [20, 50, this.maxall];
    }
  }
/* some business logic*/
}

In the html file, there is one line after mat-table:

<table mat-table matTableExporter [dataSource]="dataSource" matSort class="mat-elevation-z8"
</table>
 <mat-paginator [pageSizeOptions]="getPageSizeOptions()" showFirstLastButtons></mat-paginator>

I have implemented a function called getPageSizeOptions() to calculate the maximum page size. It will display like this: https://i.sstatic.net/11byg.png

Is there a way to replace the value "1647" with "all"? I tried referring to How to add 'All' option for Angular Material paginator?, but it didn't work.

I suspect it may require some changes in the scss style, but how? The use of mat-option:last-child doesn't seem to be effective for me.

Answer №1

Everything seems to be in order and the referenced answer is functioning properly. However, if you're not seeing your changes reflected in the browser, here are some steps you can take:

  • Perform a Hard Reload (ctrl+shift+R) of your browser, clear the Cache and History.
  • Include CSS in the dashboard.component.scss file.
  • If it's still not working, try adding !important to your css property.

Example:

 mat-option:last-child:before{
    content: 'All' !important;
    float: left;
    text-transform: none;
    top: 4px;
    position: relative;
}

mat-option:last-child .mat-option-text{
  display: none;
  position: relative;
}

Answer №2

To prevent CSS styles set in the class file from being overridden, it is important to include global CSS for "mat-option". This can be achieved by adding the following code to either style.scss or style.css (the file should be at the same level as index.html):

.mat-option:last-child:before{
   content:'all';
   // background:green;
   font-size: inherit;
   line-height: 3em;
   height: 3em;
 }

 .mat-option:last-child .mat-option-text {
    display: none;
    position: relative;
 }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show content in CSS only if the div element does not contain any child elements

Is there a way to show or hide a div conditionally based on the content of another div, using only CSS? I want to avoid using JavaScript. In the past, I've used a workaround like this: .myClass:empty:before { content: 'content added to empt ...

The mark-compacts were not efficient enough, they approached the heap limit and as a result, the allocation failed. The JavaScript

Currently working with Angular version 7.2 and encountering an issue when running ng serve: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory What does this error mean? How can it be resolved? The ...

Understanding the Purpose of the Pipe Function in Angular 2 and Typescript Observables

Recently, I encountered a situation where I needed to accept an Observer parameter in a function written in Typescript. I struggled to find a solution, reminding me of working with a delegate parameter in C#. The specific scenario involved adding a bookend ...

Is it possible for me to connect an npm run command as a task in a Gruntfile?

In the root directory of my site, I have made changes to the package.json file by adding the "scripts" hook below: "scripts": { "ngDeployDev": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ../../Scripts/ng-build-deploy/ngDeployDev.p ...

How can I ensure a div expands over another element when hovering the mouse?

I have a development div in the footer with a hover effect that expands it. However, it is currently growing underneath the top element on the site. I want it to expand on top or push the element above. Website: I've tried using position, float, and ...

Increasing size of one div when clicked while reorganizing the others

Hey there! I was thinking about creating a container with 2 rows of 3 cards inside. I am using Bootstrap 4 for my grid and layout. If you need some card examples, check out here. <div class="container"> <div class="row"> <card-elemen ...

Trouble arises when attempting to animate the movement of two distinct objects consecutively using jQuery

I am facing an issue with combining animations of two different objects so that the second one starts when the first one ends. I attempted to use a callback function, but it seems I have made some syntax errors that are causing jQuery to crash or behave un ...

I require the box element within my section element to have a full-width layout

Looking at the code in the image, you can see that I am using MUI components. Within a section, there is a box containing navigation filter links. The red part represents the section, while the white inside is the navigation link bar. My goal is for this b ...

Issue with Slick Slider: Next Arrow not visible

I'm attempting to display the next and previous arrows alongside the product slider, similar to the Slick Slider example. However, I'm facing an issue where the expected fonts are not loading properly. Below is my code: HTML <div class="s ...

Ways to access data from Firestore without needing a Subscription

I am in search of retrieving a single element (path) for a specific user from Firestore using angularfire2 / angular 6. Initially, I save the image to the Firestore database. Following that, I insert a record into the Firestore database containing the use ...

Can CSS calc() achieve modulus behavior?

Is it possible to dynamically adjust the height of an element based on screen size using calc(), while still maintaining alignment with a specified baseline grid? The height should always be a multiple of the defined variable $baseline. I've noticed ...

Interactive webpages with dynamic HTML content, similar to the design of popular platforms such

Explore the source code of Dropbox's homepage or any Soundcloud page. They utilize various scripts and minimal pure HTML content (article, main, p, div). This method of generating pages is referred to as dynamic content/HTML. The main function seems ...

`Unable to activate Bootstrap dropdown feature`

Having an issue with the dropdown menu on my Bootstrap navbar - when I click it, nothing happens. I've tried various solutions found online, such as moving the <script type="text/javascript" src="js/jquery-3.3.1.min"></script> file to the ...

When receiving a GET response after a server crash

Question: I am sending a Get request through Ajax every second and waiting for a response from the server. However, if my application crashes and I keep sending requests every second, I only receive a server timeout error (HTTP status code 502) with no oth ...

`Display PowerPoint file within your internet browser`

I need assistance with viewing pptx files in a web browser that have been uploaded to a specific location using .net core. (approximately 40 mb) (approximately 4 mb) While attempting to view both files using the code below, I am able to see the MonitorP ...

What is the best approach for transferring non-string objects between routes in Angular?

I am currently developing a custom file viewer. To achieve this, I have created a specialized component known as FileBrowserComponent that is specifically designed to be displayed when the route /files is accessed. When navigating, I include a query param ...

Prevent the function from being repeatedly triggered as the user continues to scroll

I am facing an issue with my app where new content is fetched from the API using the infinity scroll method when the user reaches near the bottom of the screen. However, if the user scrolls too fast or continuously scrolls to the bottom while new content i ...

What is the technique for linking to a different WordPress PHP file using a href?

I have a question regarding working with WordPress. I am using Stacks, a blank theme to convert an HTML template to WordPress. I need to create a hyperlink or button on a landing page that redirects to another PHP file within my website directory (e.g., lo ...

Utilizing HTML styling within a label component

The formatting of the HTML is working perfectly in this scenario. The last name is displayed with a font size of 5. lblWelcome.Text = "Welcome:<font size=''5''>" & txtSurname.Text & "</font>" Why is the HTML style ...

What is the easiest way to modify the color of a basic PNG image in a web browser?

While working on a website project, I encountered instructions for mouseover styles in the design that got me thinking: It's straightforward to achieve with javascript or css image swapping... but here's the catch. There will be multiple icon li ...