确定 Telerik MVC Grid 的所选项目和当前页面 - 客户端

发布于 2024-12-10 10:12:57 字数 500 浏览 0 评论 0原文

我正在使用带有 Ajax 数据绑定的 Telerik MVC 网格。

我想用 Telerik MVC 网格做两件事:

  1. 当选择一行时,检测(客户端)网格当前位于哪个页面以及选择了哪一行。
  2. 下次加载网格时(使用ajax ...我从不离开页面),页面返回到同一页面以显示最后的选择。 (我想我实际上只是在问是否有一种方法可以在数据加载后立即转到网格页面,而不是第 1 页)

请记住,我已经知道客户端事件。我想知道如何从事件中执行#1,以及如何从客户端或以编程方式执行#2。

编辑/更多详细信息:我想我知道我需要在这里做什么。由于我在这里使用 Ajax 加载,因此在 Telerik 代码中的某处调用了 Ajax POST。我可以看到,在 Ajax POST 期间,它们正在向控制器发送一个“page”参数。如果我可以以某种方式编辑它,我确信它会起作用 - 但我在更改该参数时遇到了麻烦。

提前致谢!

I am using the Telerik MVC grid, with Ajax data binding.

I would like to do 2 things with the Telerik MVC Grid:

  1. When a row is selected, detect (client side) which page the grid is currently on as well as which row was selected.
  2. The next time the grid is loaded (using ajax ... I never leave the page), page back to the same page to show the last select. (I guess I am really just asking if there is a way to immediately go to a page of the grid once the data is loaded, rather than page 1)

Please keep in mind, I am aware of the client side events already. I would like to know how to do #1 from the event, and #2 either from the client side or programatically somehow.

Edit/More Details: I think I know what I need to do here. Since I am using Ajax loading here, the Ajax POST is being called somewhere in the Telerik code. I can see that during that Ajax POST they are sending a "page" parameter to the controller. If I could edit that somehow, I am sure it would work - but I am having trouble changing that parameter.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2024-12-17 10:12:57

为了其他人寻找这个,我想通了:

获取网格的当前页面:
为此,我使用 jQuery 来确定哪个数字具有“选定”样式(t-state-active)来确定当前页码。示例(我的网格 ID 是“cases-grid”):

function getCurrentGridPage() {
        ///<summary>Gets the current page of the #cases-grid</summary>
        var page = $('#cases-grid .t-state-active');
        if (page.length == 0) {
            return 1; //default to page 1 when unknown
        }
        return page.text();
    }

我的问题的第二部分实际上在 Telerik 网站上有详细记录......我只是错过了一段时间。要将网格加载到特定页面(1 除外),我将以下内容添加到我的网格中:

.Pageable(pager => pager.PageTo(@Model.InitialPage))

并将 InitialPage 属性添加到我的模型中。

For the sake of anyone else looking for this, I figured it out:

Getting the current page of the Grid:
To do this, I use jQuery to determine which number has the "selected" style (t-state-active) to determine the current page number. Example (my grid id is 'cases-grid'):

function getCurrentGridPage() {
        ///<summary>Gets the current page of the #cases-grid</summary>
        var page = $('#cases-grid .t-state-active');
        if (page.length == 0) {
            return 1; //default to page 1 when unknown
        }
        return page.text();
    }

The second part of my question was actually well documented on the Telerik site ... I just missed it for awhile. To load the grid to a specific page (other than 1) I added the following to my grid:

.Pageable(pager => pager.PageTo(@Model.InitialPage))

And added the InitialPage property to my model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文