jTable条件显示隐藏基于数据所有者的编辑和删除按钮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jTable条件显示隐藏基于数据所有者的编辑和删除按钮相关的知识,希望对你有一定的参考价值。
我使用jTable显示CD信息和子表来显示该CD的评论。我希望能够仅为登录的用户显示行上的编辑删除按钮。我一直在尝试遵循以下建议:https://github.com/hikalkan/jtable/issues/113
https://github.com/hikalkan/jtable/issues/893
https://github.com/hikalkan/jtable/issues/620
可以诚实地说,我对这些例子中没有太多运气。我们被告知要在我们的任务中包含一些jquery,所以我选择将它用于我的表数据。我希望现在id只做了一些非常基本的事情!
无条件地工作jTable:
display: function (reviewData) {
//Create an image that will be used to open child table
var $img = $('<img class="child-opener-image" src="/Content/images/Misc/list_metro.png" title="List Reviews" />');
//Open child table when user clicks the image
$img.click(function () {
$('#ReviewTableContainer').jtable('openChildTable',
$img.closest('tr'),
{
title: "Your reviews on this album",
actions: {
listAction: 'childReviewActions.php?action=list&ID=' + reviewData.record.CDID,
deleteAction: 'childReviewActions.php?action=delete&ID=' + reviewData.record.CDID,
updateAction: 'childReviewActions.php?action=update&ID=' + reviewData.record.CDID
},
fields: {
userID: {
key: true,
create: false,
edit: false,
list: false
},
userName: {
title: 'User',
edit: false,
width: '20%'
},
reviewDate: {
title: 'Review date',
width: '20%',
type: 'date',
edit: false,
displayFormat: 'dd-mm-yy'
},
reviewText: {
title: 'Review',
type: 'textarea',
width: '40%'
}
},
问题620尝试:
actions: {
listAction: 'childReviewActions.php?action=list&ID=' + reviewData.record.CDID,
@if (reviewData.record.userID == <?php echo mysql_real_escape_string($_SESSION['ID']);?>)
{
deleteAction: 'childReviewActions.php?action=delete&ID=' + reviewData.record.CDID,
updateAction: 'childReviewActions.php?action=update&ID=' + reviewData.record.CDID
}
},
这种方式给了我编译错误:IF语句中的无效属性id。如果我在if语句中取出@,我得到:缺少:在属性id之后。
问题113和893尝试:
actions: {
listAction: {
url:'http://localhost/childReviewActions.php?action=list&ID=' + reviewData.record.CDID
//updateAction: {
//url:'childReviewActions.php?action=update&ID=' + reviewData.record.CDID,
//enabled: function (data) {
//return data.record.userID = <?php echo mysql_real_escape_string($_SESSION['ID']);?>;
//}
//}
},
在此我甚至无法列出子表的内容。它继续返回404找不到错误:在此服务器上找不到请求的URL / [对象对象]。有没有人有任何想法如何让这些例子工作有一个不同的例子,如何让表启用启用编辑,更新按钮?这对我来说都是新的,所以我现在道歉
rowInserted: function (event, data) {
//After child row loads. Check if the review belongs to the member logged in. If not remove the edit/delete buttons
if (data.record.userID != $user) {
data.row.find('.jtable-edit-command-button').hide();
data.row.find('.jtable-delete-command-button').hide();
}
else{
//If a review record does belong to the user set variable to true so the add new review link can be hidden after all records have been loaded
$memberReviewExists = true;
//Also needed here for when a new record is inserted
$(".jtable-add-record").hide();
}
},
recordsLoaded: function (event, data) {
if (typeof $memberReviewExists != 'undefined' && $memberReviewExists == true){
$(".jtable-add-record").hide();
$memberReviewExists = null;
}
else {
//No review currently exists for this user so show the Add review link $(".jtable-add-record").show();
}
},
recordDeleted: function (event, data) {
//User has deleted their review. Re-show the add new review link
$(".jtable-add-record").show();
}
以下对我有用。它隐藏了当前用户不是授权用户的行上的编辑/删除按钮。注意:我在mysql表中为authorizedUser添加了一列,并使用它来了解用户是否被允许。
rowInserted: function(event, data){
var $currentUser='<?php echo $_SESSION['email']?>';
if (data.record.authorizedUser != $currentUser) {
data.row.find('.jtable-edit-command-button').hide();
data.row.find('.jtable-delete-command-button').hide();
}
},
@Toni您的代码也包含asp.net代码。 @
是ASP.NET指令。
以上是关于jTable条件显示隐藏基于数据所有者的编辑和删除按钮的主要内容,如果未能解决你的问题,请参考以下文章
如果使用 jtable 事件满足某个条件,则启用 jquery-jtable 隐藏字段