MatBlazor icon indicating copy to clipboard operation
MatBlazor copied to clipboard

Programatically change page of Paged MatTable.

Open jrd6dk opened this issue 4 years ago • 1 comments

Describe the question Is there a way to Make MatTable go to a specific page. Setting CurrentPage does not seem to do it.

Blazorfiddle link https://blazorfiddle.com/s/8hra9leu

Expected behavior When setting CurrentPage the page should change. Alternative to NavigateToPage method could be public allowing the user to change page.

jrd6dk avatar Mar 18 '21 09:03 jrd6dk

@jrd6dk I tested with your code example in the MatBlazor demo and I could not recreate your issue. Seemed to work fine for me with the latest code from Git Master. I did test with the BlazorFiddle and that did not work so maybe there is something in the latest code that needs to be released. I suggest you build your own version of MatBlazor or wait until the next release.

' MatTable Items="@cars" class="mat-elevation-z5" @bind-CurrentPage="Page"> <MatTableHeader>

Name Price Horsepower </MatTableHeader> <MatTableRow> @context.Name @string.Format("${0:f2}", @context.Price) @context.Horsepower </MatTableRow> </MatTable>
    <MatTextField @bind-Value="Page" Label="Go To Page" />

    @code
    {

        public int Page = 2;

        public class Car
        {
            public string Name { get; set; }
            public double Price { get; set; }
            public int Horsepower { get; set; }

            public Car(string name, double price, int horsepower)
            {
                Name = name;
                Price = price;
                Horsepower = horsepower;
            }
        }

        Car[] cars = new[]
        {
            new Car("Volkswagen Golf", 10000, 220),
            new Car("Volkswagen Passat", 11000, 240),
            new Car("Volkswagen Polo", 12000, 110),
            new Car("Ford Focus", 13000, 200),
            new Car("Ford Fiesta", 14000, 160),
            new Car("Ford Fusion", 15000, 260),
            new Car("Ford Mondeo", 16000, 120),
            new Car("Ford Fiesta", 14000, 160),
            new Car("Ford Fusion", 15000, 260),
            new Car("Ford Mondeo", 16000, 120),
            new Car("Volkswagen Golf", 10000, 220),
            new Car("Volkswagen Passat", 11000, 240),
            new Car("Volkswagen Polo", 12000, 110),
            new Car("Ford Focus", 13000, 200),
            new Car("Ford Fiesta", 14000, 160),
            new Car("Ford Fusion", 15000, 260),
            new Car("Ford Mondeo", 16000, 120),
            new Car("Ford Fiesta", 14000, 160),
            new Car("Ford Fusion", 15000, 260),
            new Car("Ford Mondeo", 16000, 120),
        };

    }`

enkodellc avatar Mar 26 '21 19:03 enkodellc