jqgrid dataurl完成事件 [英] jqgrid dataurl completion event

查看:119
本文介绍了jqgrid dataurl完成事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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?

尽管如此,我认为您朝着正确的方向前进,并且您已经找到解决问题的正确方法. ajaxSelectOptionscomplete回调的用法可能是您可以使用的唯一方法.您写了一些冲突",但没有发布更多详细信息.

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.elemthis.optionsthis.vl. this.vl是单元格中的值(如果要编辑现有行).通常,它是将被选择的选项的名称. this.options具有树重要的属性,可以使用:this.options.dataUrlthis.options.idthis.options.name.在进行表单编辑的情况下,值this.options.idthis.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将附加partid参数(请参见上面的代码).例如,您可以使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆