Reputation: 3740
Is there any way to have Show All in Page Sizes array of Kendo Grid?
Here is my code
$("#mygrid").kendoGrid({
sortable: true,
pageable: {
pageSizes: [15,20,25,50,100,Show All]
},
How to achieve this?
Upvotes: 3
Views: 12401
Reputation: 1131
in Asp.Net MVC (Razor or server side) you can use Pageable
method PageSizes
in default values for ture overload set page size to : 5 10 20
if you need custom values use IEnumerable string collection
overload:
.Pageable(pageable => pageable.PageSizes(new string[] { "5", "10", "15", "20", "All" })
Upvotes: 2
Reputation: 521
I'm not sure why all answers looks so complicated. The answer was very easy, here is a part of the code I'm using on real project:
pageable: {
pageSize: 10,
pageSizes: [10, 25, 50, 100, "All"],
messages: {
itemsPerPage: "vendors",
display: "{0}-{1} from {2} vendors",
empty: "No data",
allPages: "Show All"
}
}
Upvotes: 6
Reputation: 8020
Try like this
Create customize toolbar with DropDown
.On DropDown Change write your Code.
View
<div id="grid">
</div>
Script
<script type="text/javascript">
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 1,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true},editable: false, },
UnitPrice: { type: "Text", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { required: true, min: 1} }
}
}
}
});
var grid= $("#grid").kendoGrid({
dataSource: dataSource,
toolbar: [
{
template: $("#template").html()
}],
navigatable: true,
pageable: {
pageSizes: [15,20,25,50,100]
},height:500,
columns: [
"ProductName",
{field: "UnitPrice", title: "Unit Price", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 }],
});
$("#grid").find(".k-grid-toolbar").insertAfter($("#grid .k-grid-content"));
$('#category').change(function(){
var value = $(this).val();
if(value != null)
{
if(value == "4")
{
grid.data("kendoGrid").dataSource.pageSize(grid.data("kendoGrid").dataSource.data().length);
}
else
{
grid.data("kendoGrid").dataSource.pageSize(parseInt(value));
}
}
});
});
</script>
<script type="text/x-kendo-template" id="template">
<div class="toolbar">
<label class="category-label" for="category">Show products by category:</label>
<select id="category" style="width: 80px">
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="4">Show All</option>
</select>
</div>
</script>
Demo: http://jsfiddle.net/mgdnE/163/
If you have any concern let me know.
Upvotes: -1