嗨有没有办法在Kendo Grid的Page Sizes数组中显示全部?
这是我的代码
$("#mygrid").kendoGrid({
sortable: true,
pageable: {
pageSizes: [15,20,25,50,100,Show All]
},
如何实现这一目标?
由于
答案 0 :(得分:5)
我不确定为什么所有答案看起来都那么复杂。 答案非常简单,这是我在真实项目中使用的代码的一部分:
pageable: {
pageSize: 10,
pageSizes: [10, 25, 50, 100, "All"],
messages: {
itemsPerPage: "vendors",
display: "{0}-{1} from {2} vendors",
empty: "No data",
allPages: "Show All"
}
}
答案 1 :(得分:0)
在Asp.Net MVC(Razor或服务器端)中,您可以使用Pageable
方法PageSizes
在ture过载的默认值中将页面大小设置为: 5 10 20
如果您需要自定义值,请使用IEnumerable string collection
overload:
.Pageable(pageable => pageable.PageSizes(new string[] { "5", "10", "15", "20", "All" })
答案 2 :(得分:-1)
试试这个
使用DropDown
创建自定义工具栏。在DropDown上更改编写代码。
查看强>
<div id="grid">
</div>
<强>脚本强>
<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>
演示:http://jsfiddle.net/mgdnE/163/
如果您有任何疑虑,请告诉我。