使用 JavaScript 过滤 Telerik MVC Grid 不适用于自定义绑定
我有一个使用自定义绑定的 Telerik MVC 网格。 使用 javascript,我将过滤器、页面和分组存储在 cookie 中,这样当用户重新加载页面时,过滤等就会恢复:
$(document).ready(function () {
//restore previously saved filters
var params = $.deparam($.cookie("MyGridCookie"));
var grid = $("#MyGrid").data("tGrid");
var refresh = false;
if (params.filterBy && params.filterBy != "") { grid.filterBy = params.filterBy; refresh = true; }
if (params.currentPage && params.currentPage != 1) { grid.currentPage = params.currentPage; refresh = true; }
if (params.orderBy && params.orderBy != "") { grid.orderBy = params.orderBy; refresh = true; }
if (refresh) grid.ajaxRequest();
});
我对没有自定义绑定的网格使用了完全相同的代码,这工作得很好。然而,在这种特殊情况下,参数command.FilterDescriptors
为空。但是,当我手动输入存储在 cookie 中的相同过滤器时,过滤效果很好。
显然,当启用自定义绑定时,与没有自定义绑定的网格相比,Telerik 网格在过滤方面会做一些不同的事情。有谁知道如何解决这个问题?
I have a Telerik MVC grid which uses custom binding.
Using javascript I store the filter, page and grouping in a cookie, such that when the user reloads the page, the filtering etc. is restored:
$(document).ready(function () {
//restore previously saved filters
var params = $.deparam($.cookie("MyGridCookie"));
var grid = $("#MyGrid").data("tGrid");
var refresh = false;
if (params.filterBy && params.filterBy != "") { grid.filterBy = params.filterBy; refresh = true; }
if (params.currentPage && params.currentPage != 1) { grid.currentPage = params.currentPage; refresh = true; }
if (params.orderBy && params.orderBy != "") { grid.orderBy = params.orderBy; refresh = true; }
if (refresh) grid.ajaxRequest();
});
I've used the exact same code for grids without custom binding and this works just fine. However, in this particular case, the parameter command.FilterDescriptors
is empty. But when I manually input the same filter which is stored in the cookie, the filtering works just fine.
So apparently, when custom binding is enabled, the telerik grid does something different when it comes to filtering compared to a grid without custom binding. Does anyone know how to resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,问题在于过滤器存储在 CompositeFilterDescriptors 中。问题解决了。
Indeed the problem was with the filters being stored in CompositeFilterDescriptors. Problem solved.
您是否尝试使用
grid.rebind();
而不是grid.ajaxRequest();
Did you try
grid.rebind();
instead ofgrid.ajaxRequest();