如何隐藏 Ajax 绑定 Telerik Grid for MVC 上的“编辑”按钮?
我使用 Telerik Extensions for MVC。在一页上,我使用网格来显示状态消息。我想显示所有具有正 status_id 的状态消息的编辑按钮。
我之前已经使用服务器绑定网格和 CellAction 完成了此操作。不过,我试图将其更改为 Ajax 绑定网格,但我无法弄清楚如何隐藏特定行的按钮。
也许有一种方法可以从 JavaScript 引用特定单元格,并以这种方式隐藏它?
谢谢!
I use Telerik Extensions for MVC. On one page I use a grid to display status messages. I want to show edit buttons for all status messages that have a positive status_id.
I have previously done this using a server bound grid and CellAction. However I am trying to change it into an Ajax bound grid, but I cannot figure out how to hide the buttons for specific rows then.
Is there, perhaps, a way to reference a specific cell from JavaScript, and hide it that way?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我意识到这个问题是不久前发布的,但我希望我的答案对其他人有用。
在您的数据模型中传递一个字段。在本例中,它是“RemoveDelete”,并且由于它明确用于根据预定条件删除“删除”按钮,因此它被设置为隐藏在网格中。如果网格中显示的数据已包含您要检查的条件,则无需执行此操作。
在网格中...
脚本...
删除编辑按钮...
隐藏最后一列使用
综上所述,这允许您预先确定要逐行显示的按钮。
I realize this question was posted some time ago but I am hoping my answer will prove useful to others.
In your data model pass a field. In this case it is "RemoveDelete" and since it is used expressly to remove the Delete button based on a predetermined condition it is set to be hidden in the grid. If data displayed in your grid already contains the condition you want to examine then you don't have to do this.
In the Grid...
the script...
to remove the Edit button...
to hide the last column use
With all that being said, this allows you to predetermine what buttons you want displayed on a row by row basis.
我设法以一种有点古怪的方式解决了这个问题:
我为“OnRowBound”事件添加了一个函数,它将包含“编辑”按钮的单元格的内部文本设置为空。
将函数添加到事件:
函数:
I managed solve it in a somewhat hacky way:
I added a function for the "OnRowBound"-event, that set the innerText of the cell containing the Edit button to nothing.
Adding the function to the event:
The function:
@AZee 目前接受的答案很好,但自从 Telerik 从“MVC 扩展”过渡到 KendoUI 包装器后将不再有效。请参阅 Telerik 网格迁移页面 。靠近底部的是使用
DataBound
网格事件代替onRowDataBound
事件的说明。 另请注意中的view()
以前的链接不可用,因此您需要使用_data
。最后,类前缀从t-
更改为k-
。这些更改的影响: 设置事件处理程序:
以及事件处理程序本身:
@AZee's currently accepted answer is good, but will no longer work since Telerik transitioned from "MVC extensions" to KendoUI wrappers. See Telerik Grid Migration page. Near the bottom are instructions for using the
DataBound
grid event in place of theonRowDataBound
event. Note also that theview()
in the former link isn't available, so you'll need to use_data
. Finally, the class-prefixes were changed fromt-
tok-
.The impact of these changes: to set up the event handler:
And the event handler itself:
就我而言,我使用了不同的 jQuery 函数来隐藏“编辑”按钮,看起来像这样。
创建样式:
在 onRowDataBound javascript 函数中:
希望,这有帮助。
In my case I used a different jQuery function to hide the Edit button and looks like that.
Create a style:
In the onRowDataBound javascript function:
Hope, this help.