前端之家收集整理的这篇文章主要介绍了
dojo小例子(32)dgrid增加filter搜索功能2,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<form id="filterForm">
Filter by Last Name: <input type="text"name="filter">
<button type="submit">Filter</button>
</form>
<div id="grid"></div>
require([
"dojo/dom","dojo/on","dojo/store/Memory","dgrid/OnDemandGrid"
],function(dom,on,Memory,OnDemandGrid) {
varform = dom.byId("filterForm"),store = newMemory({ data: [
{ id: 1,firstName: "Bryan",lastName: "Forbes"},{ id: 2,firstName: "Kenneth",lastName: "Franqueiro"},{ id: 3,firstName: "Colin",lastName: "Snover"},{ id: 4,firstName: "Kris",lastName: "Zyp"}
] }),grid = newOnDemandGrid({
columns: {
"firstName":"First Name","lastName":"Last Name"
},sort:"lastName",store: store
},"grid");
on(form,"submit",function(event) {
varvalue = form.elements.filter.value;
// Filter lastName,matching against the input text
grid.set("query",{ lastName: value });
// Since we're using a form,prevent normal submission
event.preventDefault();
});
});
1
grid.set("query",{ lastName: newRegExp(value,"i") });
这种方式,结合使用JsonRest可以把filter参数通过url发送到
后台,供条件
查询使用,实现
后台过滤 原文http://www.sitepen.com/blog/2013/09/06/dojo-faq-how-can-i-add-filtering-controls-to-dgrid/