Telerik MVC Grid,真正的 Ajax 自定义绑定
我使用的网格看起来像这样:
Html.Telerik().Grid(Model).Name("preciousGrid").
... bla bla bla..
.ClientEvents(events => events.OnDataBinding("onDataBinding"))
.Columns(columns =>
{
columns.Bound(o => o.Date);
columns.Bound(o => o.Name);
是的,我完全忽略 .DataBinding
的东西来使用自定义 ajax 调用。为什么?我需要向服务器发送更多数据,而不是简单的 id。收集数据的唯一方法是遍历 DOM 元素。因此,Telerik 建议的所有方法都不适用于我的情况。
一切正常 - 在 onDataBinding 中,收集必要的数据并将其发送到服务器后,服务器返回结果,网格显示该数据。
但仍然有一个问题。分页不起作用。页脚显示类似的内容:
有什么想法吗?
UPD:哦...也许我应该向服务器发送寻呼信息并基于此返回结果?怎么做呢?你能给我看一个样品吗?
UPD2:默认情况下,GridCommand 命令不会将分页信息发送到服务器(如果我在 $.ajax 中省略它,并且仍然在操作方法中放置 GridCommand 参数,它会向控制器发送一些内容,但 PageSize 始终等于 10 (默认) value),并且 Page 始终为 1。所以我想我必须将这些值硬编码到 $.ajax 中,但我不知道如何在客户端上获取 PageSize 和 Page 值?
I'm using grid that looks like that:
Html.Telerik().Grid(Model).Name("preciousGrid").
... bla bla bla..
.ClientEvents(events => events.OnDataBinding("onDataBinding"))
.Columns(columns =>
{
columns.Bound(o => o.Date);
columns.Bound(o => o.Name);
Yes, I'm totally ignoring .DataBinding
stuff to use custom ajax call. Why? I need to send to the server more data, rather than a simple id. And the only way to gather that data is by traversing DOM elements. So, none of the methods suggested by Telerik wouldn't work in my case.
Everything works - in onDataBinding, after the necessary data gathered and sent to the server, server returns results, grid displays that data.
But still there is a problem. Paging doesn't work. And the footer shows something like that:
Any ideas?
UPD: Oh... maybe I should send to the server paging info and return results based on that? How to do that? Can you show me a sample?
UPD2: GridCommand command doesn't send Paging info to the server by default(if I omit it in $.ajax and still put a GridCommand parameter in the action method it would send something to the controller, but PageSize is always equals 10 (default value), and Page is always 1. So I guess I have to hardcodedly include these values in $.ajax. But I don't know how can I get PageSize and Page values on the client?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在进行自定义数据绑定,则必须自己处理分页和排序,如下所示。 演示网站上的示例非常合理......
在您看来:
If you're doing custom data binding, you must handle the paging and sorting yourself, something like that shown below. The example on the demo site is pretty reasonable...
in the view you have:
好吧...显然你可以做真正的自定义ajax绑定
你必须定义数据绑定虽然它不会被网格使用,但你需要它才能使网格可分页。
接下来,在
Grid_onDataBinding
javascript 函数中,您必须执行类似的操作Ok... apparently you can do truly custom ajax binding
You have to define databinding although it's not gonna be used by the grid, but you need it in order to be able to make the grid Pageable.
Next, in the
Grid_onDataBinding
javascript function you have to do something like that