This is a migrated thread and some comments may be shown as answers.

PageSizes with GetOptions

4 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 02 Mar 2021, 10:10 PM

     Hi. I'm trying to find the current PageSizes for a grid. I know that I can get the current PageSize with GetOptions, but I haven't find a way to get all the PageSizes.

    Is there a way to do it using GetOptions? or the only way will be to get the values directly from the dropdown?

    Thanks.

 

4 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 05 Mar 2021, 05:20 PM

Hi Alex,

You can get all pageSizes like this:

var grid = $("#grid").data("kendoGrid");
console.log(grid.getOptions().pageable.pageSizes)

As for the currently selected option in the pageSizes dropdown, it matches the pageSize value, so you can get it as shown below:

grid.pager.pageSize()

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Alex
Top achievements
Rank 1
answered on 05 Mar 2021, 11:21 PM

That worked, thanks.

Now, how can I use setOptions to set both the PageSize and PageSizes?

I can do either of them independently, but can't find a way to do it together. This is the code I use to set the PageSize:

        grid.setOptions({
            groupable: true
            , pageable: { pageSize: selDefaultPageSize }
            , dataSource: { pageSize: selDefaultPageSize }
            , height: selGridHeight
        });

And this is what I use the PageSizes

        var selPageSizesTest = [20, 50, 100];
        grid.setOptions({
            groupable: true
            , pageable: { pageSizes: selPageSizesTest }
            , height: selGridHeight
        });

Can I set them both together at the same time?

Thanks. 

0
Ivan Danchev
Telerik team
answered on 10 Mar 2021, 05:32 PM

Alex,

The following way of setting both options worked out for me:

<input type="button" class="k-button k-primary" value="Set Page Options" onclick="setGridPageOptions()" />

<script>
  
  function setGridPageOptions() {
    var grid = $("#grid").data("kendoGrid");
    
    var selPageSizesTest = [20, 50, 100];
    var selDefaultPageSize = 50;
    
    grid.setOptions({
      groupable: true,
      pageable: { 
        pageSizes: selPageSizesTest,
        pageSize: selDefaultPageSize 
      },
      dataSource: { 
        pageSize: selDefaultPageSize 
      }, 
      height: 500
    });
  }
</script>

Try it out and let me know whether it works as expected.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Alex
Top achievements
Rank 1
answered on 23 Mar 2021, 03:22 PM
It worked, thanks.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Alex
Top achievements
Rank 1
Share this question
or