如何在 jqgrid 中有条件地显示链接?

发布于 2024-12-07 00:08:40 字数 319 浏览 0 评论 0原文

我有一个 jqgrid,并且有一个自定义格式化程序,可以根据我的需要格式化和显示链接。这确实工作正常,但我有一个问题。我想有条件地显示链接。我怎样才能做到这一点?

例如。如果此人是管理员,则向他显示所有链接,例如编辑、删除等(这些链接映射到控制器中的操作方法)。但如果该人是非管理员用户,则仅显示“查看”链接并隐藏所有其他链接。

我只需要一个如何实现这一目标的总体策略。其中一种策略是我向 json 数据添加一个布尔字段,该字段表示是否显示编辑、删除等链接。然后在我的格式化程序中,我可以查看行数据并决定是否返回显示链接。

有更好的方法吗?

I have a jqgrid and I have a custom formatter for it which formats and displays links as per my needs. This does work fine but I have a problem. I want to display links conditionally. How can I do that?

For Eg. If the person is Admin then show him all links like edit, delete etc (these links map to action methods in controller). But if the person is NonAdmin user then only show View link and hide all other links.

I just need a general strategy of how to accomplish this. One of the strategy would be I add a boolean field to my json data which would signify whether the link of edit, delete etc is to be shown or not. Then in my formatter and I can look at the row data and decide whether to return show link or not.

Is there any better way of doing this?

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

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

发布评论

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

评论(1

清泪尽 2024-12-14 00:08:42

您建议在服务器的 JSON 响应中添加附加数据听起来不错。值得一提的是,您应该以任何方式阻止非管理员进行数据编辑。隐藏或不创建用于编辑的链接不是安全功能,但主要是 GUI 改进以防止不允许的操作。如果您在实施时遇到一些技术问题,您应该在问题中包含相应的代码。

如果您还使用表单编辑,则可以使用 演示 href="https://stackoverflow.com/questions/7056859/jqgrid-resolve-the-grid-pager-id-dinamically/7057838#7057838">答案或另一个演示来自 另一个答案也可能对您有帮助。

You suggestion with additional data in the JSON response from the server sounds OK. It's important to mention, that you should prevent data editing for non-admins in any way. The hiding or not creating the link for editing is not a security feature, but mostly GUI improvement to prevent actions which are not permitted. If you has some technical problems with the implementation you should include the corresponding code in your question.

If you use additionally form editing, then the demo from the answer or another demo from the another answer could be also helpful for you.

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