开发者

How can you conditionally display links in jqgrid?

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开发者_如何学Go or not.

Is there any better way of doing this?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜