我有一个允许用户过滤的网格.如果用户更改用于填充网格的搜索词,则上一次搜索的过滤器仍然存在.
<label for="UserName"> User Name:</label> <%= Html.TextBox("UserName","") %> <input id="btnSearch" type="submit" value="Submit" /> </p> <div class="<%= "t-" + Html.GetCurrentTheme() %>" style="width: 400px;"> <%= Html.Telerik().Grid<ADGroup>() .Name("Groups") .Columns(columns=> { columns.Add(c => c.GroupName).Width(350); }) .Sortable() .Filterable() .Pageable(paging => paging.PageSize(20) ) .Ajax(ajax => ajax.Action("_GetGroups","GroupSearch",new { userName = "John Doh" })) .BindTo((IEnumerable<ADGroup>)ViewData["Groups"]) %> </div>
当按下btnSearch时,我已经触发了gird的重新绑定.
<% Html.Telerik().ScriptRegistrar() .OnDocumentReady(() => { %> var groupsGrid = $('#Groups').data('tGrid'); $('#btnSearch') .live("click",function() { var user = $('#UserName').val(); // rebind the related grid groupsGrid.rebind({ userName: user }); }); <% });
%GT;
我知道我可以添加以下代码来调出过滤器菜单,但是我希望能够在.rebind()调用发生之前或之后自动清除过滤器.
$('.t-grid-filter:first') .trigger('click');