我正在使用jqGrid 4.4.0進行內聯編輯。爲了這個問題,我的網格有四列:ID列(SomeGridRowId),帶有jQuery自動完成(Autocomplete)的文本列,單個字符文本列(SingleChar)和隱藏列(CanEditSingleChar)。我需要根據CanEditSingleChar
列的值啓用或禁用單字符列的編輯。我已經在使用onSelectRow
和setColProp
的現有行上工作,但出於某種原因,我無法在新插入的行上使其正常工作。如果我添加一個新行並從自動完成中選擇一個值,SingleChar
列是總是不可編輯。我使用Chrome和IE開發人員工具瀏覽了Javascript;列值和屬性得到正確設置,但SingleChar
列的editable
屬性不反映此情況。根據另一列中的自動完成結果更改jqGrid文本列的可編輯屬性
我爲巨大的代碼片斷表示歉意,但我不想留下任何東西。
$("#coolGrid").jqGrid({
url: '@Url.Action("GetCoolGridData")',
postData: {
someId: function() { return $("#someId").val(); },
otherStaticArg: function() { return 1; }
},
datatype: 'json',
mtype: 'POST',
loadonce: true,
cellsubmit: 'clientArray',
editurl: 'clientArray',
scroll: true,
pager: $("#coolGridPager"),
rowNum: 200,
sortname: 'SomeGridRowId',
sortorder: 'asc',
viewrecords: true,
height: '100%',
colNames: ['SomeGridRowId', 'CanEditSingleChar', 'Autocomplete', 'SingleChar'],
colModel: [
{ name: 'SomeGridRowId', index: 'SomeGridRowId', hidden: true },
{ name: 'CanEditSingleChar', index: 'CanEditSingleChar', hidden: true },
{
name: 'Autocomplete',
index: 'Autocomplete',
width: 220,
editable: true,
edittype: 'text',
editoptions: {
dataInit: function (elem) {
$(elem).autocomplete({
source: '@Url.Action("GetSomeGridAutocomplete")',
minLength: 2,
select: function (event, ui) {
var rowId = getRowId($(this));
if (ui.item) {
$("#coolGrid").jqGrid('setCell', rowId, 'CanEditSingleChar', ui.item.CanEditSingleChar, '', '');
$("#coolGrid").jqGrid('setCell', rowId, 'Autocomplete', ui.item.label, '', '');
setSingleCharEditMode(rowId);
}
}
});
}
}
},
{
name: 'SingleChar',
index: 'SingleChar',
width: 10,
editable: true, //default to true, most are editable
edittype: 'text'
}
],
onSelectRow: function (clickedRow) {
if (clickedRow && clickedRow != $.coolGridLastSelectedRow) {
$("#coolGrid").jqGrid('saveRow', $.coolGridSelectedRow, false, 'clientArray');
$.coolGridLastSelectedRow = clickedRow;
}
setSingleCharEditMode($.coolGridLastSelectedRow);
$("#coolGrid").jqGrid('editRow', $.coolGridLastSelectedRow, true);
},
afterInsertRow: function (rowid, rowdata, rowelem) {
if (rowid == 'new_row') { //shown solely for completeness, pretty sure this is not the problem
var newRowIndex = $("#coolGridNewRowIndex").val();
if (!newRowIndex)
newRowIndex = 1;
var newRowId = rowid + "_" + newRowIndex;
$("#new_row").attr('id', newRowId);
newRowIndex++;
$("#coolGrid").val(newRowIndex);
$("#coolGrid").jqGrid('setSelection', newRowId, true);
}
}
});
$("#coolGrid").jqGrid('navGrid', '#coolGridPager',
{
add: false,
del: false,
edit: false,
search: false,
beforeRefresh: function() {
$("#coolGrid").jqGrid('setGridParam', { datatype: 'json' });
}
});
$("#coolGrid").jqGrid('inlineNav', '#coolGridPager',
{
edit: false,
add: true,
addtext: "Add",
save: false,
cancel: false,
restoreAfterSelect: false,
addParams: {
position: 'last',
addRowParams: {
keys: true
}
}
});
而且setSingleCharEditMode
功能:
function setSingleCharEditMode(rowid) {
var rowData = $("#coolGrid").jqGrid('getRowData', rowid);
if (rowData.CanEditSingleChar === "false") {
$("#coolGrid").jqGrid('setColProp', 'SingleChar', { editable: false });
} else {
$("#coolGrid").jqGrid('setColProp', 'SingleChar', { editable: true });
}
}
我試過的東西,整體轉換,通過一堆其他SO問題膛線,一派瘋狂....都無濟於事。我已經使出了我的頭髮。我如何控制另一列上的自動完成select
之後的一列中的editable
屬性,全部在新行上?
編輯
我有一個working example up here,終於。如果添加一行,然後選擇3210列中的任意一個「非典型*」,則可以重現此行爲。
謝謝你的深思熟慮的迴應。我正在努力在線獲取示例。 –
你有沒有進展?你怎麼看待分配這個賞金?我認爲在寬限期結束之前不會再有任何答案。 – Wolfram
對不起,Wolfram,上週忙碌的一週,我沒有時間去完成一個完整的工作範例。我希望今天能夠處理它,但賞金卻是你的(儘管我不確定它爲什麼會將它分成100)。 –