JQGrid Edittype:使用dataurl的“选择”返回,而不保存选择值
我有一个edittype为的JQGrid列:“选择”使用dataUrl返回一个帐户列表,其中包含不同帐户组的组 我的问题:保存行时,没有将任何值传递到我的Select列的editurl。如果删除了的,则会将一个值传递给我的Select列的editurl 描述:对于我的列数据,我返回的是帐户名,而不是值,因此当网格加载时,会显示名称 在线编辑中编辑行时,将调用dataUrl并显示选择列表,并为行数据选择我的帐户 然后,我从选择列表中选择一个新帐户,然后按enter键保存。选定的帐户值不会传递给该列的editurl函数。如果从中删除,则帐户值将传递给editurl函数 我不确定我是否做错了什么(没有设置网格参数) 希望你能帮助我 提前感谢, 克里斯 我的网格代码:JQGrid Edittype:使用dataurl的“选择”返回,而不保存选择值,jqgrid,optgroup,Jqgrid,Optgroup,我有一个edittype为的JQGrid列:“选择”使用dataUrl返回一个帐户列表,其中包含不同帐户组的组 我的问题:保存行时,没有将任何值传递到我的Select列的editurl。如果删除了的,则会将一个值传递给我的Select列的editurl 描述:对于我的列数据,我返回的是帐户名,而不是值,因此当网格加载时,会显示名称 在线编辑中编辑行时,将调用dataUrl并显示选择列表,并为行数据选择我的帐户 然后,我从选择列表中选择一个新帐户,然后按enter键保存。选定的帐户值不会传递给该列
$(document).ready(
function () {
var lastSelection;
var grid = jQuery("#BankTransactions");
grid.jqGrid({
url: '/DropDown/GridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['TransactionLineId', 'TransactionId', 'BankTransactionId', 'Number', 'Amount', 'Category'],
colModel: [
{ name: 'transactionLineId', index: 'transactionLineId', editable: true, editrules: { edithidden: true }, hidden: true, width: 40, align: 'left' },
{ name: 'transactionId', index: 'transactionId', editable: true, editrules: { edithidden: true }, hidden: true, width: 40, align: 'left' },
{ name: 'bankTransactionId', index: 'bankTransactionId', editable: true, editrules: { edithidden: true }, hidden: true, width: 40, align: 'left' },
{ name: 'Number', index: 'Number', width: 100, align: 'left', sortable: false },
{ name: 'Amount', index: 'SubAmount', editable: true, width: 100, align: 'right', sortable: false, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'class="BankTranEdit"' }, formatter: 'currency', formatoptions: { decimalSeparator: '.', thousandsSeparator: ',', decimalPlaces: 2, defaultValue: ' '} },
{ name: 'CategoryIdURL', index: 'CategoryIdURL',
editable: true,
edittype: 'select',
//formatter: 'select',
editoptions: { dataUrl: "/DropDown/CategorySelectList" },
width: 220,
align: 'left'
},
],
pager: jQuery('#pager'),
rowNum: 100,
rowList: [25, 50, 100],
editurl: "/Dropdown/GridSave",
sortname: 'Number',
sortorder: "desc",
viewrecords: true,
width: 1250,
height: 450,
onCellSelect: function (rowid, iCol, cellContent, e) {
grid.restoreRow(lastSelection);
grid.editRow(rowid, true, null, null, null, null, null);
lastSelection = rowid;
}
});
});
输出/下拉/网格数据:
{"total":1,
"page":1,
"records":6,
"rows":[
{"id":165,"cell":["165","249","125","DM000249","1500.00","Sales"]},
{"id":145,"cell":["145","229","105","SM000229","100.00","Rent"]},
{"id":153,"cell":["153","237","113","SM000237","38.07","Bank Fees"]},
{"id":185,"cell":["185","269","145","SM000269","750.00","Cash Discounts"]},
{"id":194,"cell":["194","278","154","SM000278","13.29","Rent"]},
{"id":211,"cell":["211","295","171","SM000295","100.00","Rent"]}]
}
/Dropdown/CategorySelectList的输出
<select>
<optgroup label='Expenses'>
<option value='42'>Accounting Fees</option>
<option value='60'>Bank Fees</option>
<option value='23'>Bank Service Charges</option>
<option value='24'>Books and Publications</option>
<option value='25'>Cash Discounts</option>
<option value='43'>Rent</option>
</optgroup>
<optgroup label='Income'>
<option value='19'>Sales</option>
<option value='20'>Services</option>
<option value='21'>Interest Income</option>
<option value='22'>Other Income</option>
</optgroup>
</select>
jqGrid的当前版本不适用于的内部 我发现在某些情况下使用的可能会有所帮助。所以我调试了一下jqGrid代码,发现只需要修改jqGrid的两行代码,即grid.inlinedit.js的行或jqGrid 4.1.1中jquery.jqGrid.src.js的行8262-8263
tmp[nm] = $("select>option:selected",this).val();
tmp2[nm] = $("select>option:selected", this).text();
到
或者只是为了
tmp[nm] = $("select option:selected",this).val();
tmp2[nm] = $("select option:selected",this).text();
来解决这个问题
如果需要支持具有多个:true属性的选择:
应该以与上面相同的方式修改grid.inlinedit.js的另一行,该行具有select>选项:selected。要使jqGrid具有multiple:true属性并使用dataUrl属性,必须修复grid.inlinedit.js的另一行。一个人需要改变
if(cm[i].edittype == "select" && cm[i].editoptions.multiple===true && $.browser.msie){
$(elc).width($(elc).width());
}
例如,下面是一个例子
if(cm[i].edittype === "select" && typeof(cm[i].editoptions)!=="undefined" &&
cm[i].editoptions.multiple===true &&
typeof(cm[i].editoptions.dataUrl)==="undefined" && $.browser.msie) {
$(elc).width($(elc).width());
}
此更改将阻止在从dataUrl加载$.ajax请求之前设置非常小的select宽度。可能应该在grid.common.js中相应的$.ajax调用的事件处理程序中放置相同的宽度修复,其中将加载dataUrl的数据。我在IE9中测试了我的演示,不需要对IE9进行修复
您可以在这里看到带有固定jqGrid代码的演示:。您应该考虑到,服务器上没有将在editurl中使用的/Dropdown/GridSave代码。不过,您将在Firebug的Fiddeler中看到,将发送到服务器的发布数据确实包含有关所选项目的信息。如果您想让演示在本地运行,您应该将editurl修改为“clientArray”,并可能将Additional loadonce:true设置为true。您可以修改您的问题并将其与“/DropDown/CategorySelectList”和“/DropDown/GridData/”的输出一起追加吗。有了这些数据,我们可以尝试重现您的问题。谢谢Oleg,我已经用请求的输出更新了问题。第一次就应该这么做,我的错。
if(cm[i].edittype === "select" && typeof(cm[i].editoptions)!=="undefined" &&
cm[i].editoptions.multiple===true &&
typeof(cm[i].editoptions.dataUrl)==="undefined" && $.browser.msie) {
$(elc).width($(elc).width());
}