Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change page size dynamically in Kendo UI Grid

I am having a Kendo UI grid showing more than 1000 data. I also have a dropdown list for different page size - 15, 25, 50, 100. On selection of a page size, how can we change the page size of Kendo UI grid?

like image 499
Ashmah Avatar asked Jul 04 '12 13:07

Ashmah


People also ask

How do I change the page size in kendo grid?

You can set the page size in the combobox change event. (Also see JSBin example.) Show activity on this post. That's great.

How do I change the max height on a kendo grid?

Table cells and rows ignore min and max height styles in general. Height behaves like min-height. What you can do is use a column template and wrap the cell content in a div with a max-height and overflow style.

What is Pageable in kendo grid?

kendo:grid-pageable-messagesThe text messages displayed in pager. Use this option to customize or localize the pager messages. More documentation is available at kendo:grid-pageable-messages.


4 Answers

You can set the page size in the combobox change event. (Also see JSBin example.)

$("#comboBox").kendoComboBox({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: [
        { text: 1 },
        { text: 2 },
        { text: 3 },
        { text: 4 },
        { text: 5 }
    ],
    change: function(e) {
      var grid = $("#grid").data("kendoGrid");
      grid.dataSource.pageSize(parseInt(this.value()));  // this.value() being the value selected in Combo
    }
});
like image 192
Daniel Avatar answered Oct 24 '22 20:10

Daniel


Here's the latest using ASP.NET MVC Helper

.Pageable(pager => pager.PageSizes(new int[] {20, 50, 100})) // Enable paging
like image 28
Rick Glos Avatar answered Oct 24 '22 22:10

Rick Glos


Its also built into the latest version of the grid by doing the following in js

pageable: {
    pageSizes: [10, 25, 50, 100]
}

http://docs.kendoui.com/api/web/pager

like image 24
Cragly Avatar answered Oct 24 '22 22:10

Cragly


Rick has told it in a good way a more explained if some one misses where is it to be done here is a code piece to know where is it to be done with a screen short snap

@(Html.Kendo().Grid(Model)
      .Name("SiteUserGrid")
      .Columns(columns =>
          {
              columns.Bound(u => u.LastName).Title("Last Name");
              columns.Bound(u => u.FirstName).Title("First Name");
              columns.Bound(u => u.UserName).Title("User Name");
              columns.Bound(u => u.EmailAddress).Title("Email Address");
              columns.Bound(u => u.AccessLevel).Title("Access Level");
              columns.Bound(u => u.Status).Title("Status");
              columns.Bound(u => u.UserId).Filterable(f => f.Enabled(false)).ClientTemplate(actionColumnTemplate).Title("Action").Sortable(false).Width(190);
          })
      .Pageable(pageable => pageable.ButtonCount(10))

.Pageable(pager => pager.PageSizes(new int[] {5,10,15,20,30,50,100}))

      .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
      .Sortable()
      .Filterable(filterable => filterable
                                    .Extra(false)
                                    .Operators(operators => operators
                                                                .ForString(str => str.Clear()
                                                                                     .StartsWith("Starts with")
                                                                                     .Contains("Contains")
                                                                                     .IsEqualTo("Is equal to")
                                                                ))

Hope this helps

like image 32
Dare Devs Avatar answered Oct 24 '22 20:10

Dare Devs