有两种获取方式:
- 您让 Kendo UI 在顶部生成,然后将其移动到底部
- 您将其生成到底部。
第一种方法很快,如果你不需要标题工具栏是最好的。只需添加以下代码:
$("#grid).data("kendoGrid").wrapper.append($(".k-toolbar"));
在这里查看:http://jsfiddle.net/OnaBai/WsRqP/1/
第二种方法 - 使用您在原始问题中提到的示例作为基础 - 将是这样的:
第 1 步:定义模板,您可以使用与示例中相同的模板:
<script type="text/x-kendo-template" id="template">
<div class="toolbar">
<label class="category-label" for="category">Show products by category:</label>
<input type="search" id="category" style="width: 150px"/>
</div>
</script>
第 2 步:初始化网格,就像您现在所做的那样(在我的情况下,我不会将工具栏作为页眉,而只是作为页脚):
var grid = $("#grid").kendoGrid({
dataSource: {
type : "odata",
transport : {
read: "http://demos.kendoui.com/service/Northwind.svc/Products"
},
pageSize : 20,
serverPaging : true,
serverSorting : true,
serverFiltering: true
},
height : 430,
sortable : true,
pageable : true,
columns : [
{ field: "ProductID", title: "Product ID", width: 100 },
{ field: "ProductName", title: "Product Name" },
{ field: "UnitPrice", title: "Unit Price", width: 100 },
{ field: "QuantityPerUnit", title: "Quantity Per Unit" }
]
}).data("kendoGrid");
第 3 步:添加一个 dataBound 处理程序,用于在网格初始化后创建页脚。我们必须在dataBound 上执行此操作,否则 Grid 的格式仍然不正确,并且页脚看起来会出错。我已经在一个单独的函数中实现了创建页脚工具栏,以免弄乱dataBound,以防你在这里做更多的事情。
dataBound : function () {
initFooterToolbar(this, kendo.template($("#template").html()));
}
第 4 步:实现此initFooterToolbar:
function initFooterToolbar(grid, template) {
if (!this._footer) {
this._footer = $("<div class='k-toolbar k-grid-toolbar k-widget'></div>")
.append(template);
grid.wrapper.append(this._footer);
// Other code for initializing your template
...
}
}
initFooterToolbar 所做的是首先检查它是否尚未初始化,否则如果您进行分页刷新数据,您可能最终会使用多个页脚工具栏。
最后将工具栏附加到grid.wrapper。
因此,创建页脚工具栏的重要部分是调用 grid.wrapper.append(...) 并在网格已创建时执行此操作。
这里修改的原始示例:http://jsfiddle.net/OnaBai/WsRqP/