【发布时间】:2011-11-10 04:57:51
【问题描述】:
虽然 jqgrid editform 中的自动完成和选择都将所选标签放入单元格中,但 select 会将值 (id) 放入 postdata 数组中,而自动完成会将标签放入 postdata 数组中。
有没有办法让编辑选项的自动完成来发布项目值(id)而不是标签?
这是我在...中使用自动完成的 jqgrid 代码段
$('#tab3-grid').jqGrid({
colNames:['Workorder', 'wo.CUID',.....],
colModel:[
.
.
.
{name:'wo.CUID', index:'cu.LastName', width:120, fixed:true, align:'center', sortable:true, editable:true, edittype:'text',
editoptions:{dataInit:function(el){$(el).autocomplete({ source: 'php/customer-ac-script.php'
, minLength: 1
})
}
},
formoptions:{rowpos: 1, label:'Customer', elmprefix:'* '},
editrules:{required:true}
},
.
.
.
$('#tab3-grid').jqGrid('navGrid', '#tab3-pager',
{view:true, closeOnEscape:true, cloneToTop:true}, // general parameters that apply to all navigation options below.
{jqModal:true, navkeys:[true,38,40], savekey:[true,13]}, // edit options.
{jqModal:true, navkeys:[true,38,40], savekey:[true,13], reloadAfterSubmit:false, afterSubmit: addRecordID}, // add options.
{jqModal:true, afterSubmit: serverMessage}, // del options.
{jqModal:true}, // search options.
{jqModal:true, navkeys:[true,38,40]} // view options.
);
php代码段:
// construct autocomplete select.
$i = 0;
while($row = mysql_fetch_assoc($result)) {
$output[$i][$crudConfig['id']] = $row['CUID'];
$output[$i][$crudConfig['value']] = $row['LastName'];
logMsg(__LINE__,'I','cu.CUID: '.$row['CUID'].', cu.LastName: '.$row['LastName']);
$i++;
}
// encode to json format and send output back to jqGrid table.
echo json_encode($output);
logMsg(__LINE__,'I','Send json output back to jqGrid table: '.json_encode($output));
会不会像在自动完成选择事件下或者在editform提交之前或者之后的grid下调用一个函数那么简单?
另外,我在 jqgrid 文档中的 datainit 中注意到了这个注释:上面写着...
注意:有些插件需要元素在 DOM 中的位置和 因为在将元素插入 DOM 之前引发了此事件 您可以使用 setTimeout 函数来完成所需的操作。
是否缺少包含 settimeout 函数会导致问题?
【问题讨论】:
-
您能否更准确地描述您的问题?例如,哪种格式具有返回“php/customer-ac-script.php”的数据。 jQuery UI Autocomplete 允许您完全控制将在自动完成的上下文菜单中显示的标签和在用户选择项目后将插入到
<input>控件中的值。所以你应该准确定义输入数据的格式并实现select,可能还有_renderItem。 -
我的意思是附加到 datainit: 的 jquery 自动完成功能确实起作用,但是当提交编辑表单时,postdata 数组包含自动完成显示文本而不是与其关联的 id。我已将 php 代码段添加到原始帖子中,以向您展示 jqgrid 得到了什么。
标签: jqgrid autocomplete jquery-ui-autocomplete