【发布时间】:2013-12-31 15:15:21
【问题描述】:
我想根据在不同单元格中找到的数据启用/禁用单元格的内联编辑。
我正在使用格式化程序操作来显示一个编辑图标,这似乎意味着我无法通过 onSelectRow 进行任何检查,因为单击编辑图标时似乎不会触发它。在阅读了一些不同的问题/解决方案后,我认为我可以简单地禁用/启用整个专栏的编辑,但这似乎在我下面的代码中不起作用,而且我认为这将是一条糟糕的路线,因为看起来像一个用户可以在同一显示图标内单击多行上的编辑图标,并且每一行将同时显示可编辑。似乎最好的方法是在单元格级别本身启用/禁用编辑,但我已经通过操作中的 afterInsertRow 和 onEdit 尝试过,但似乎对单元格是否可以编辑没有任何影响。
这是使用 JQGrid 4.5.2、jQuery UI 1.9.1 和 jQuery 1.8.2
<script>
$(document).ready(function() {
var noteIcon = '<div title="Job Details" style="float:left; margin-left:5px;" class="ui-pg-div ui-inline-edit" onmouseover="jQuery(this).addClass(\'ui-state-hover\');" onmouseout="jQuery(this).removeClass(\'ui-state-hover\');"><span class="ui-icon ui-icon-note"></span></div>';
getColumnIndexByName = function(grid,columnName) {
var cm = grid.jqGrid('getGridParam','colModel');
for (var i=0,l=cm.length; i<l; i++) {
if (cm[i].name===columnName) {
return i; // return the index
}
}
return -1;
};
jQuery.extend(jQuery.jgrid.defaults, {
altRows:true,
altclass:'myAltRowClass',
datatype: "json",
jsonReader: {
root: "ROWS",
page: "PAGE",
total: "TOTAL",
records: "RECORDS",
cell: "",
id: "0"
},
emptyrecords: "No jobs to display.",
rowList: [25,50,100],
viewrecords: true,
height: "auto",
loadonce: true,
footerrow: true,
loadComplete: function (data) {
var $self = $(this), i = getColumnIndexByName($self, 'action');
$("tbody > tr.jqgrow > td:nth-child("+(i+1)+") > div:nth-child(1)",$self[0]).click(function(e) {
var tr=$(e.target,$self[0].rows).closest("tr.jqgrow");
e.preventDefault();
window.location.href = 'CenterView.cfm?table=ORDER_JOBS&ID=' + tr[0].id + '&backurl=%3DJobsInbox%2Ecfm%3FPICK%5FDMS%5FCENTERID%3D15';
});
},
colNames: [ "ID", "Delivery Type", "Service Type", "Pre-Commit", "Survey Name", "Client", "Order ID", "Job Number", "Client Reference","Internal Reference", "Type", "Product Name", "Submitted For", "Sales Coordinator", "Order Date", "Requested Date", "Standard Date", "Inbox Date", "Delivery Hold", "Pre-Commit Hold", "Analyst", " ", "Actions" ],
colModel: [
{ name: "id", index: "id", hidden: true, key: true },
{ name: "delivery_type", index: "delivery_type", width: 70, formatter:'select', stype:'select', edittype:'select', editoptions: { value: ":All;External Delivery:External Delivery;Internal Data Access:Internal Data Access;Internal Delivery:Internal Delivery" } },
{ name: "service_type", index: "service_type", width: 65, searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']} },
{ name: "isprecommit", index: "isprecommit", width: 50, align: "center", formatter:'select', stype:'select', edittype:'select', editoptions: { value: ":All;false:No;true:Yes" } },
{ name: "survey_name", index: "survey_name", searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']}, formatter:'showlink', formatoptions:{baseLinkUrl:'LinkStation.cfm', addParam: '&Type=JobsInboxSurvey&PICK_DMS_CENTERID=15'} },
{ name: "corpname", index: "corpname", searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']}, formatter:'showlink', formatoptions:{baseLinkUrl:'LinkStation.cfm', addParam: '&Type=JobsInboxClient&PICK_DMS_CENTERID=15'} },
{ name: "orderid", index: "orderid", width: 40, formatter:'showlink', formatoptions:{baseLinkUrl:'LinkStation.cfm', addParam: '&Type=JobsInboxOrder&PICK_DMS_CENTERID=15'}, search:false },
{ name: "jobsnumber", index: "jobsnumber", width: 60, searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']}, formatter:'showlink', formatoptions:{baseLinkUrl:'CenterView.cfm', addParam: '&table=ORDER_JOBS&backurl=%3DJobsInbox%2Ecfm%3FPICK%5FDMS%5FCENTERID%3D15'} },
{ name: "clientref", index: "clientref", width: 60, searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']} },
{ name: "internal_reference", index: "internal_reference", width: 33, formatter:'select', stype:'select', edittype:'select', editoptions: { value: ":;EOM:EOM;NO GO:NO GO" } },
{ name: "survey_type", index: "survey_type", width: 35, align: "center", formatter:'select', stype:'select', edittype:'select', editoptions: { value: ":All;2D:2D;3D:3D" } },
{ name: "product_name", index: "product_name", searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']} },
{ name: "submitted_for", index: "submitted_for", width: 70, searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']} },
{ name: "sales_coordinator", index: "sales_coordinator", width: 70, searchoptions:{sopt:['cn','eq','bw','bn','nc','ew','en']} },
{ name: "order_date", index: "order_date", width: 50, align: "center", search:false, datefmt: 'mm/dd/yy' },
{ name: "requested_date", index: "requested_date", width: 50, align: "center", search:false, datefmt: 'mm/dd/yy' },
{ name: "dt_standard", index: "dt_standard", width: 50, align: "center", search:false, datefmt: 'mm/dd/yy' },
{ name: "inbox_date", index: "inbox_date", width: 50, align: "center", search:false, datefmt: 'mm/dd/yy' },
{ name: "isdeliveryhold", index: "isdeliveryhold", sortable: true, search: true, width: 50, align: "center", formatter:'select', stype:'select', editable:true, edittype:'select', editoptions: { value: ":;false:No;true:Yes" } },
{ name: "isprecommithold", index: "isprecommithold", sortable: true, search: true, width: 50, align: "center", formatter:'select', stype:'select', editable:true, edittype:'select', editoptions: { value: ":;false:No;true:Yes" } },
{ name: "analyst", index: "analyst", width: 115, align: "center", sortable: true, search: true, formatter:'select', stype:'select', editable:true, edittype:'select', editoptions: { value: ":;michael-19810202:Mike Hares;sara-20061004:Sara Kathleen Lampman" } },
{ name: 'action', index: 'action', sortable: false, search: false, width: 25, formatter: function() { return noteIcon; } },
{ name: "act", index: "act", width: 55, align: "center", sortable: false, search:false, formatter: "actions",
formatoptions: {
keys: true, delbutton: false, afterSave: function() { $(this).jqGrid('setGridParam', {datatype:'json'}); $(this).trigger('reloadGrid', [{page:1}]); },
onEdit:function(rowid) {
var localRowData = $(this).jqGrid('getLocalRow', rowid);
if(localRowData.isprecommit == true) {
// $(this).jqGrid('setColProp', 'isprecommithold', {editable:true});
}
else {
// $(this).jqGrid('setColProp', 'isprecommithold', {editable:false});
$(this).setCell(rowid,"isprecommithold","",'not-editable-cell');
}
}
}
}
],
editurl: "Components/JobsInbox.cfc?method=SetJobUpdate&UPDATEDBY=aaron-20040630",
afterInsertRow:
function(rowid, aData){
/*
if(aData.isprecommit == false) {
$(this).setCell(rowid,"isprecommithold","",'not-editable-cell');
}
*/
if(aData.isdeliveryhold) {
$(this).setCell(rowid,"isdeliveryhold","",{"background":"#FF6A6A"});
}
}
});
$('#Jobs').jqGrid({
url: "Components/JobsInbox.cfc?method=GetJobGrid&PICK_DMS_CENTERID=15&CFDateFormat=MM/DD/YY",
caption: "Jobs Inbox",
pager: $('#JobsPager')
});
$('#Jobs').jqGrid('filterToolbar', { searchOperators: false, ignoreCase: true });
$('#Jobs').jqGrid('navGrid', '#JobsPager', { add: false, edit: false, del: false, refresh: false });
$('#Jobs').jqGrid('navButtonAdd', '#JobsPager', { caption: "", buttonicon: "ui-icon-refresh", title: $.jgrid.nav.refreshtitle, onClickButton: function() { $(this).jqGrid('setGridParam', {datatype:'json'}); $(this).trigger('reloadGrid', [{page:1}]); } });
});
</script>
<style type="text/css">
.myAltRowClass { background-color: #ECF6FC; background-image: none; }
/* Wrap in header cell */
.ui-jqgrid .ui-jqgrid-htable th div {
height:auto;
overflow:hidden;
padding-right:4px;
padding-top:2px;
position:relative;
vertical-align:text-top;
white-space:normal !important;
}
/* Wrap in table cell */
.ui-jqgrid tr.jqgrow td {
white-space: normal !important;
height:auto;
vertical-align:text-top;
padding-top:2px;
}
span.cellWithoutBackground {
display:block;
background-image:none;
margin-right:-2px;
margin-left:-2px;
height:14px;
padding:4px;
}
</style>
【问题讨论】:
标签: jqgrid