当我从下拉列表中选择一个月时,我的数据网格成功过滤,但是当我尝试在onLoad上过滤它时,它只是不过滤。下拉列表成功显示当前月份,网格也应显示当前月份数据。
<script type="text/javascript">
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.XmlStore");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.date");
theMonth = new Date();
dojo.addOnLoad(function()
{
dojo.byId('monthInput').value = month_name[(theMonth.getMonth()+1)];
var filterString='{month: "' + theMonth.getMonth() + '"}';
var filterObject=eval('('+filterString+')');
dijit.byId("eventGrid").filter(filterObject);
}
);
var eventStore = new dojox.data.XmlStore({url: "events.xml", rootItem: "event", keyAttribute: "dateSort"});
function monthClick() {
var ctr, test, rtrn;
test = dojo.byId('monthInput').value;
for (ctr=0;ctr<=11;ctr++)
{
if (test==month_name[ctr])
{
rtrn = ctr;
}
}
var filterString='{month: "' + rtrn + '"}';
var filterObject=eval('('+filterString+')');
eventGrid.setQuery(filterObject);
}
</script>
</head>
<body class="tundra">
<div id="header" dojoType="dijit.layout.ContentPane" region="top" class="pfga"></div>
<div id="menu" dojoType="dijit.layout.ContentPane" region="left" class="pfga"></div>
<div id="content" style="width:750px; overflow:visible" dojoType="dijit.layout.ContentPane" region="center" class="pfga">
<div dojotype="dojo.data.ItemFileReadStore" url="months.json" jsID="monthStore"></div>
<div id="pagehead" class="Heading1" >Upcoming Events</div>
<p>
<input dojoType="dijit.form.FilteringSelect" store="monthStore" searchAttr="month" name="id" id="monthInput" class="pfga" onChange="monthClick()" />
</p>
<table dojoType="dojox.grid.DataGrid" store="eventStore" class="pfga" style="height:500px; width:698px" clientSort="true" jsID="eventGrid">
<thead>
<tr>
<th field="date" width="80px">Date</th>
<th field="description" width="600px">Description</th>
</tr>
<tr>
<th field="time" colspan="2">Details</th>
</tr>
</thead>
</table>
</div>
<div id="footer"></div>
答案 0 :(得分:1)
filter()是客户端过滤。它应该在构建网格并加载数据后调用。
您想要设置网格的查询参数。这确定了商店中哪些记录到达网格。它类似于“select * from table”。
过滤器用于过滤这些结果,因此当用户从客户端过滤进行选择时,请调用过滤器。过滤器类似于在“select * from table”中添加where子句。
答案 1 :(得分:0)
这可能是一个异步问题。也就是说,你的addOnLoad是执行的,因为DOM已加载,但你的数据还没有完成加载。您可以尝试将月过滤逻辑连接到以下而不是addOnLoad吗?也许它看起来像这样:
dojo.connect(eventGrid, "_onFetchComplete", function(){
dojo.byId('monthInput').value = month_name[(theMonth.getMonth()+1)];
var filterString='{month: "' + theMonth.getMonth() + '"}';
var filterObject=eval('('+filterString+')');
dijit.byId("eventGrid").filter(filterObject);
});