jqgrid dataurl完成事件 [英] jqgrid dataurl completion event
问题描述
我正在使用jQuery来获取零件编号的供应商列表. 然后,一旦出现编辑表单,我想加载有关供应商/零件号组合的一些额外数据.问题是在执行beforeShowForm方法之前,获取供应商的dataurl方法(我在beforeInitData方法中调用)没有完成.因此,第一次加载表单时,我没有供应商来查找.在dataUrl方法完成以获取额外数据之后,是否可以运行该函数?
I am using jQuery to get a list of suppliers for a part number. I then want to load some extra data about the supplier/part number combination once the edit form appears. The problem is that the dataurl method (which I am calling in the beforeInitData method) to get the suppliers does not complete before the beforeShowForm method executes. Therefore I do not have a supplier to look up when the form first loads. Is there a way to run the function after the dataUrl method completes to get the extra data?
我尝试了 JQGrid编辑选项dataurl不使用ajax get吗?并成功了,但是我知道会有冲突,因为每个请求都会调用ajaxSelectOptions方法,有时我的请求将来自具有不同要求的不同地方.
I have tried JQGrid editoptions dataurl not using ajax get? and got it going but I know there will be conflicts because the ajaxSelectOptions method gets called for every request and sometimes my requests will be coming from different places with different requirements.
这是我用于网格的代码:
Here is the code that I am using for my grid:
jQuery("#receiptPartsTable").jqGrid('editGridRow',"new",
{
height:400,
width:800,
reloadAfterSubmit:false,
recreateForm: true,
beforeInitData: function(form)
{
var selectedPart = rowData.part;
var selectedPartQty = rowData.qty;
//Getting list of suppliers
$("#receiptPartsTable").jqGrid('setColProp', 'supplier', { editoptions:{dataUrl:'getSuppliersForPart.php?part=' + rowData.part} });
},
beforeShowForm: function(form)
{
var selectedPart = rowData.part;
var selectedPartQty = rowData.qty;
$('#part').val(selectedPart);
$('#qty').val(selectedPartQty);
//$('#supplier').val() is not set yet;
var supplier = $('#supplier').val();
//This method is getting called before there is a supplier
getPartDetails(rowData.part, supplier);
//Set up onChange listener. After selecting a supplier, get the part details
$('#supplier').change(function() {
var supplier = $('#supplier').val();
getPartDetails(selectedPart, supplier);
});
}
推荐答案
您未发布要使用的jqGrid的定义.您执行上述代码的上下文也不太清楚.您是否从当前选中的行之前获得rowData
?您在哪里定义它?
You posted no definition of jqGrid which you use. The context in which you execute the above code is also not quite clear. Do you get rowData
before from the currently selected row? Where you define it?
尽管如此,我认为您朝着正确的方向前进,并且您已经找到解决问题的正确方法. ajaxSelectOptions
的complete
回调的用法可能是您可以使用的唯一方法.您写了一些冲突",但没有发布更多详细信息.
Nevertheless I think that you went in the correct direction and that you found already the correct way to solve the problem. The usage of complete
callback of ajaxSelectOptions
is probably the only way which you can use. You wrote about some "conflicts", but not posted more details.
我建议您在complete
回调内部检查this
的属性. jqGrid设置context
选项(请参见该行)(与您已经找到自己的答案答案完全一样).因此,您可以在complete
回调中使用this.elem
,this.options
和this.vl
. this.vl
是单元格中的值(如果要编辑现有行).通常,它是将被选择的选项的名称. this.options
具有树重要的属性,可以使用:this.options.dataUrl
,this.options.id
,this.options.name
.在进行表单编辑的情况下,值this.options.id
和this.options.name
相同.在进行内联编辑的情况下,this.options.id
将具有rowid,而_
将作为前缀.它使您可以在complete
回调中针对使用dataUrl
的不同选择执行不同的代码.
I would recommend you to examine properties of this
inside of complete
callback. jqGrid set context
option (see the line) of the $.ajax
call (exactly like in the answer which you already found yourself). So you can use this.elem
, this.options
and this.vl
inside of complete
callback. this.vl
is the value from the cell in case if editing of existing row. Typically it's the name of the option which will be selected. this.options
has tree important properties which you can use: this.options.dataUrl
, this.options.id
, this.options.name
. In case of form editing are the values this.options.id
and this.options.name
the same. In case of inline editing this.options.id
will have rowid and _
ad the prefix. It gives you the possibility to execute different code inside of complete
callback for different selects where you use dataUrl
.
再说一遍.在大多数情况下,您可以从beforeInitData
中删除对setColProp
的调用,并使用答案和另一个:
One more remark. In the most cases you can remove call of setColProp
from the beforeInitData
and use the approach suggested in the answer and the another one:
ajaxSelectOptions: {
data: {
id: function () {
return $("#receiptPartsTable").getGridParam('selrow');
},
part: function () {
return rowData.part;
}
},
complete: function (jqXHR, textStatus) {
var columName = this.options.name, response = jqXHR.responseText;
...
}
}
您只能使用editoptions: {dataUrl: "getSuppliersForPart.php"}
该URL将附加part
和id
参数(请参见上面的代码).例如,您可以使用getRowData
代替id
从其他列获取内容,这些内容基于当前选定行的rowid.
You can use just editoptions: {dataUrl: "getSuppliersForPart.php"}
The URL will be appended with part
and id
parameters (see the above code). Instead of id
you could use getRowData
to get content from other columns based of rowid of currently selected row for example.
这篇关于jqgrid dataurl完成事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!