我有一个带编辑/删除/添加功能的jqgrid。我想仅为具有管理员权限的用户显示这些操作项。除了管理员权限之外的所有人都不应该在jqgrid导航栏中看到编辑/删除或添加按钮。 我正在使用PHP来验证用户身份。现在,登录到网站的用户可以添加,编辑和删除操作。
这是我的jqgrid代码:
function doOneGrid()
{
var data={};
data.PRODUCT = prod;
data.RELEASE=rel;
prod = $("#productCombo").val();
rel = $("#releaseCombo").val();
jQuery("#list").jqGrid({
url:"/ProductionScheduler/controller/productcontroller.php?q=2&prod="+prod+"&rel="+rel,
datatype: "json",
type:"POST",
height: 450,
colNames:['Product','Version','ProductionVersion','Status','ProductionStatus','Production','PackagingStatus','PackagingDate','SanityStatus','To_Sanity', 'STStatus','To_ST','eeQSStatus','To_eeQS','GAStatus','To_GA','Notes','Milestones'
],
colModel:[
{name:'Product',index:'Product', width:150,align:"center",sorttype:"string",editable:true,edittype:"select",editoptions:{value:"Default:;OSV:OSV;OSB:OSB;SBC:SBC;LogManager:LogManager;Fusion for Outlook:Fusion for Outlook;Fusion for Lync/MOC:Fusion for Lync/MOC"},formoptions:{rowpos:1},editrules:{required:true}},
{name:'Version',index:'Version', width:150,align:"center",sorttype:"string",hidden:true,editable:true,hidedlg: true,editrules: { edithidden: true },edittype:"select",editoptions:{value:"V8:V8;V7R1:V7R1;V7:V7;V6:V6"}},
{name:'ProductionVersion',index:'ProductionVersion',title:"false",editable:true, width:250,align:"center",sorttype:"string",cellattr: function () { return 'style="white-space: normal;"'}},
{name:'Status',index:'Status', width:100,align:"center",sorttype:"string",editable:true,edittype:"select",editoptions:{value:"Planned:Planned;Produced:Produced;In Sanity:In Sanity; In System Test:In System Test; In Field Trial:In Field Trial; In GA:In GA;TBD:TBD;N/A:N/A;Removed:Removed;Canceled:Canceled"}},
{name:'ProductionStatus',index:'ProductionStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'Production',index:'ProductionDate', width:100,align:"center",editable:true,sorttype:"date"},
{name:'PackagingStatus',index:'PackagingStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'Packaging',index:'PackagingDate', width:100,align:"center",sorttype:"date",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true }},
{name:'SanityStatus',index:'SanityStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'To_Sanity',index:'Sanity_Regression_Date', width:100, align:"center",sorttype:"date",editable:true},//jsonmap:"cell.1.value"
{name:'STStatus',index:'STStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'To_ST',index:'ST_Date', width:100, align:"center",sorttype:"date",editable:true},//formatter:myFormatter},
{name:'eeQSStatus',index:'eeQSStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'To_eeQS',index:'eeQS_Date', width:100, align:"center",sorttype:"date",editable:true},//formatter:myFormatter},
{name:'GAStatus',index:'GAStatus', width:100,align:"center",hidden:true,editable:true,hidedlg: true, editrules: { edithidden: true },edittype:"select",editoptions:{value:"Default:;Actual:Actual;Plan:Planned"}},
{name:'To_GA',index:'GA_Date', width:100, align:"center",sorttype:"date",editable:true},//,formatter:myFormatter},
{name:'Notes',index:'Notes', width:200, align:"center",sorttype:"string",editable:true,cellattr: function () { return 'style="white-space: normal;"'}},//cellattr: function () { return 'style=\"background:orange\"'}},
{name:'Milestones',index:'Milestones', width:100, align:"center",sorttype:"string",editable:true,cellattr: function () { return 'style="white-space: normal;"'}},
],
rowNum:25,
rowList:[50,100,300],
pager: '#pager',
sortname: 'ProductionVersion',
sortorder: "desc",
editurl:"/ProductionScheduler/controller/action.php",
viewrecords: true,
autowidth: true,
caption: "Schedule",
onCellSelect:function(rowid,icol, cellcontent,e){
var dataFromTheRow=jQuery('#list').jqGrid ('getRowData', rowid);
},
subGrid : true,
subGridUrl: "/ProductionScheduler/controller/subgrid.php?q=1",
subGridModel: [
{ name : ['Product','Release','Field_Updated','Old_Value', 'New_Value','Update_Type','Name_Updated','Date_Created','Notes'],
width : [80,80,80,80,80,80,80,80],
params:['Product','ProductionVersion'],
sortname:['DateCreated'],
sortorder: "asc"
} ]
});
jQuery("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true,defaultSearch:"cn"});
jQuery("#list").jqGrid('navGrid','#pager',{del:true,add:true,edit:true,search:true,cloneToTop:true},{},{},{},{multipleSearch:true});
}
答案 0 :(得分:0)
有两种方法可以解决这个问题:
保留按钮,但是,从返回的数据中检索“权限”值,然后在寻呼机的添加/删除/更新按钮中使用该值,绑定点击事件以确定用户是否可以编辑/删除或显示一条消息,说明他们无权访问。
将自己的按钮添加到寻呼机,并将内置的编辑/删除按钮设置为false。获取权限值,然后在loadComplete中确定这些按钮的显示属性。 您可以将其存储在隐藏字段中,而不是从为网格检索的数据中获取值。
var permission = $('#hidden').val();
$('#list').jqGrid({
...
loadComplete: function() {
if (permission === xxx){
$('#edit').hide();
}
})
.navButtonAdd('#list', { id: "edit", ... }
}