Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqgrid在更改另一个单元格时更改可编辑单元格的值(相关列)_Javascript_Jquery_Json_Jqgrid - Fatal编程技术网

Javascript jqgrid在更改另一个单元格时更改可编辑单元格的值(相关列)

Javascript jqgrid在更改另一个单元格时更改可编辑单元格的值(相关列),javascript,jquery,json,jqgrid,Javascript,Jquery,Json,Jqgrid,这是网格。 我的折扣列有一个autocomplete,它的值来自另一个json变量 这是我的json数组,折扣数据来自这里 [ {"id":0.56,"label":"Adams Rite Less 50\/12","value":"Adams Rite Less 50\/12"}, {"id":0.44,"label":"ASSA Less 44","value":"ASSA Less 44"}, {"id":0.603,"label":"BARON ACCESSORIES AN

这是网格。

我的折扣列有一个autocomplete,它的值来自另一个json变量

这是我的json数组,折扣数据来自这里

[
  {"id":0.56,"label":"Adams Rite Less 50\/12","value":"Adams Rite Less 50\/12"},
  {"id":0.44,"label":"ASSA Less 44","value":"ASSA Less 44"},
  {"id":0.603,"label":"BARON ACCESSORIES AND STICKS Less 60.3","value":"BARON ACCESSORIES AND STICKS Less 60.3"},
  {"id":0.704,"label":"BARON STD AND CUSTOM DOORS Less 70.4","value":"BARON STD AND CUSTOM DOORS Less 70.4"},
  {"id":0.617,"label":"BARON STD AND CUSTOM FRAMES Less 61.7","value":"BARON STD AND CUSTOM FRAMES Less 61.7"},
  {"id":0.704,"label":"BARON STD PALLET DOORS Less 70.4","value":"BARON STD PALLET DOORS Less 70.4"},
  {"id":0.145,"label":"Bobrick 10\/5","value":"Bobrick 10\/5"},
  {"id":0.6175,"label":"BREMNER HMD","value":"BREMNER HMD"},
  {"id":0.6073,"label":"BREMNER HMF","value":"BREMNER HMF"},
  {"id":0.44,"label":"Eff Eff Less 44","value":"Eff Eff Less 44"}
]
我想做的是

(1) 更改贴现值后,成本列应根据此公式进行更改

new Cost = (1-0.145)*List Price Cell's value (in this case 999)
值0.145来自json的id列

(2) 更改折扣值后,ExtCost列应根据此值进行更改

New Ext Cost = Quantity * new Cost
数量是最左边的单元格

这是我的网格相关代码

    var lastsel2;
    jQuery(document).ready(function(){
        var autocompleteSource;
        $.getJSON("{{ asset('app_dev.php/GetDiscount') }}", function(json){
            autocompleteSource = json;
        });
        var cont;
        jQuery("#list").jqGrid({
            url: "{{ asset('/app_dev.php/_thrace-datagrid/data/view_PO_details') }}",
            postData: {
                masterGridRowId: {{ editid }}
            },
            datatype: "json",
            mtype: 'POST',
            colNames: ['', 'Released', 'Attachments', 'Quantity', 'Received', 'Item #', 'Vendor Item #', 'List Price', 'Discount', 'Cost', 'ExtCost', 'Lead Time', 'System Key', 'PO Item Note', 'PO Required Date', 'Confirm #','Confirm Date', 'VQ #', 'Reference', 'VQ Ref', 'UOM', 'Type', 'Last Update', 'Updated By', 'FSC', 'Door #', 'Queue', 'RTE#'],
            colModel: [
                {
                    name: "POD_UISelected",
                    index: "o.POD_UISelected",
                    editable: true,
                    edittype: 'checkbox',
                    editoptions: {value: "True:False"},
                    formatter: "checkbox",
                    formatoptions: {disabled: false},
                    align: 'center',
                    jsonmap: "cell.0",
                    width: '70'
                },
                {
                    name: "POD_Released",
                    index: "o.POD_Released",
                    editable: true,
                    edittype: 'checkbox',
                    editoptions: {value: "Yes:No"},
                    formatter: "checkbox",
                    formatoptions: {disabled: false},
                    align: 'center',
                    jsonmap: "cell.1",
                    width: '70'
                },
                {
                    name: "I_LinkHasFiles",
                    index: "o.I_LinkHasFiles",
                    editable: false,
                    edittype: 'checkbox',
                    editoptions: {value: "True:False"},
                    formatter: "checkbox",
                    formatoptions: {disabled: true},
                    align: 'center',
                    jsonmap: "cell.2",
                    width: '70'
                },
                {
                    name: "POD_OrderQty",
                    index: "o.POD_OrderQty",
                    editable: true,
                    align: 'center',
                    jsonmap: "cell.3",
                    width: '100'
                },
                {
                    name: "POD_QtyReceived",
                    index: "o.POD_QtyReceived",
                    editable: true,
                    align: 'center',
                    jsonmap: "cell.4",
                    width: '100'
                },
                {name: "POD_ItemNumID #", index: "o.POD_ItemNumID", editable: false, align: 'center', jsonmap: "cell.5"},
                {
                    name: "POD_VendorItemNum",
                    index: "o.POD_VendorItemNum",
                    editable: false,
                    align: 'center',
                    jsonmap: "cell.6"
                },
                {
                    name: "POD_VendorListPrice",
                    index: "o.POD_VendorListPrice",
                    editable: true,
                    align: 'center',
                    formatter: 'currency',
                    formatoptions: {prefix: '$', suffix: '', thousandsSeparator: ','},
                    jsonmap: "cell.7"
                },
                {
                    name: "POD_VendorDiscount",
                    index: "o.POD_VendorDiscount",
                    editable: true,
                    jsonmap: "cell.8",
                    editoptions: {
                       dataInit: function(elem) {
                           var $self = $(this), // save the reference to the grid
                                   $elem = $(elem); // save the reference to <input>
                            $(elem).autocomplete({
                                source: autocompleteSource,
                                select: function (event, ui) {
                                    var $tr = $elem.closest("tr.jqgrow"), newCost, rowid = $tr.attr("id"),
                                            orderQty = parseFloat($tr.find("input[name=POD_OrderQty]").val()),
                                            listPrice = parseFloat($tr.find("input[name=POD_VendorListPrice]").val());
                                    if (ui.item) {
                                        console.log(orderQty);
                                        console.log(listPrice);
                                        newCost = (1 - parseFloat(ui.item.id)) * listPrice;
                                        $self.jqGrid("setRowData", rowid, {
                                            POD_UnitCost: newCost,
                                            POD_ExtCost: orderQty * newCost
                                        });
                                    }
                                },
                                minLength: 0,
                                minChars: 0,
                                autoFill: true,
                                mustMatch: true,
                                matchContains: false,
                                scrollHeight: 220


                            }).on('focus', function(event) {
                                var self = this;
                                $(self).autocomplete( "search", "");
                            });
                        }
                    }
                },
                {
                    name: "POD_UnitCost",
                    index: "o.POD_UnitCost",
                    editable: false,
                    align: 'center',
                    formatter: 'currency',
                    formatoptions: {prefix: '$', suffix: '', thousandsSeparator: ','},
                    jsonmap: "cell.9"
                },
                {
                    name: "POD_ExtCost",
                    index: "o.POD_ExtCost",
                    editable: false,
                    align: 'center',
                    formatter: 'currency',
                    formatoptions: {prefix: '$', suffix: '', thousandsSeparator: ','},
                    jsonmap: "cell.10"
                },
                {name: "POD_Leadtime", index: "o.POD_Leadtime", editable: false, jsonmap: "cell.11"},
                {
                    name: "POD_Stocked",
                    index: "o.POD_Stocked",
                    editable: false,
                    edittype: 'checkbox',
                    editoptions: {value: "True:False"},
                    formatter: "checkbox",
                    formatoptions: {disabled: true},
                    align: 'center',
                    jsonmap: "cell.12"
                },
                {name: "POD_Note", index: "o.POD_Note", editable: true, jsonmap: "cell.13"},
                {
                    name: "POD_ReqDate",
                    index: "o.POD_ReqDate",
                    editable: true,
                    jsonmap: "cell.14.date",
                    editoptions:{size:20,
                        dataInit:function(el){
                            $(el).datepicker({dateFormat:'yy-mm-dd'});
                        },
                        defaultValue: function(){
                            var currentTime = new Date();
                            var month = parseInt(currentTime.getMonth() + 1);
                            month = month <= 9 ? "0"+month : month;
                            var day = currentTime.getDate();
                            day = day <= 9 ? "0"+day : day;
                            var year = currentTime.getFullYear();
                            return year+"-"+month + "-"+day;
                        }
                    }
                },
                {name: "POD_ConfrmNum", index: "o.POD_ConfrmNum", editable: true, jsonmap: "cell.15"},
                {
                    name: "POD_PromDate",
                    index: "o.POD_PromDate",
                    editable: true,
                    jsonmap: "cell.16.date",
                    editoptions:{size:20,
                        dataInit:function(el){
                            $(el).datepicker({dateFormat:'yy-mm-dd'});
                        },
                        defaultValue: function(){
                            var currentTime = new Date();
                            var month = parseInt(currentTime.getMonth() + 1);
                            month = month <= 9 ? "0"+month : month;
                            var day = currentTime.getDate();
                            day = day <= 9 ? "0"+day : day;
                            var year = currentTime.getFullYear();
                            return year+"-"+month + "-"+day;
                        }
                    }
                },
                {name: "VQ_PK", index: "o.VQ_PK", editable: false, jsonmap: "cell.17"},
                {name: "pod_reftext", index: "o.pod_reftext", editable: false, jsonmap: "cell.18"},
                {name: "VQ_VRef", index: "o.VQ_VRef", editable: false, jsonmap: "cell.19"},
                {name: "POD_UOM", index: "o.POD_UOM", editable: false, jsonmap: "cell.20"},
                {name: "POD_ItemType", index: "o.POD_ItemType", editable: false, jsonmap: "cell.21"},
                {name: "POD_DateUpdated", index: "o.POD_DateUpdated", editable: false, jsonmap: "cell.22.date"},
                {name: "POD_UpdatedSysUser", index: "o.POD_UpdatedSysUser", editable: false, jsonmap: "cell.23"},
                {name: "I_FSC", index: "o.I_FSC", editable: false, jsonmap: "cell.24"},
                {name: "PjD_NumID", index: "o.PjD_NumID", editable: false, jsonmap: "cell.25"},
                {name: "POD_QueueSourceText", index: "o.POD_QueueSourceText", editable: false, jsonmap: "cell.26"},
                {name: "RTP_PK_E", index: "o.RTP_PK_E", editable: false, jsonmap: "cell.27"}
            ],
            beforeSelectRow: function (rowid, e) {
                var $target = $(e.target), $td = $target.closest("td"),
                        iCol = $.jgrid.getCellIndex($td[0]),
                        colModel = $(this).jqGrid("getGridParam", "colModel");
                if (iCol >= 0 && $target.is(":checkbox")) {
                    if(colModel[iCol].name == "POD_UISelected")
                    {
                        $('#list').setSelection(rowid, true);
                        $("#list").jqGrid('saveRow', rowid, { //same rowid value used in 'addRowData' method above
                            succesfunc: function (response) {
                                $('#list').trigger( 'reloadGrid' );
                                return true;
                            }
                        })
                    }
                }
                return true;
            },
            onSelectRow: function(id){
                if(id && id!==lastsel2){
                    jQuery('#list').jqGrid('restoreRow',lastsel2);
                    jQuery('#list').jqGrid('editRow',id,true);
                    lastsel2=id;
                }
            },
            jsonReader: {repeatitems: false},
            height: 400,
            rowNum: 50,
            rowTotal: 1000000,
            autowidth: true,
            gridview: true,
            autoencode: false,
            pager: '#pager',
            shrinkToFit: true,
            sortable: true,
            sortname:"o.POD_ReqDate",
            sortorder: "desc",
            viewrecords: true,
            //multiselect: true,
            loadonce:false,
            rowList: [50, 100, 500, 1000],
            editurl: "{{ asset('/app_dev.php/_thrace-datagrid/row-action/view_PO_details') }}"
        });
        jQuery("#list").jqGrid('navGrid',"#pager",{ del:false, add:false, edit:false},
        {editData: {PO_PK: {{ editid }}}},
        {editData: {PO_PK: {{ editid }}}},
        {editData: {PO_PK: {{ editid }}}},
        {multipleSearch:true}
        );
        jQuery("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true});
        jQuery('#list').jqGrid('gridResize');
        $("#productEdit_V_PK").prop("disabled", true);
    });
var lastsel2;
jQuery(文档).ready(函数(){
var自动完成源;
$.getJSON({asset('app_dev.php/GetDiscount')}}),函数(json){
autocompleteSource=json;
});
var cont;
jQuery(“#list”).jqGrid({
url:“{asset('/app_dev.php/_-thrace-datagrid/data/view_PO_details')}”,
postData:{
masterGridRowId:{{editid}
},
数据类型:“json”,
mtype:“POST”,
colNames:['','发布','附件','数量','接收','项目','供应商项目','标价','折扣','成本','ExtCost','交货期','系统密钥','采购订单项目注释','采购订单要求日期','确认日期','确认日期','参考','参考','计量单位','类型','上次更新','金融服务委员会','门','队列','RTE',
colModel:[
{
名称:“POD_UISelected”,
索引:“o.POD_.Uisselected”,
是的,
edittype:“复选框”,
editoptions:{value:“True:False”},
格式化程序:“复选框”,
formatoptions:{已禁用:false},
对齐:'居中',
jsonmap:“cell.0”,
宽度:“70”
},
{
名称:“POD_发布”,
索引:“o.POD_发布”,
是的,
edittype:“复选框”,
编辑选项:{value:“是:否”},
格式化程序:“复选框”,
formatoptions:{已禁用:false},
对齐:'居中',
jsonmap:“cell.1”,
宽度:“70”
},
{
名称:“I_LinkHasFiles”,
索引:“o.I_LinkHasFiles”,
可编辑:false,
edittype:“复选框”,
editoptions:{value:“True:False”},
格式化程序:“复选框”,
formatoptions:{disabled:true},
对齐:'居中',
jsonmap:“cell.2”,
宽度:“70”
},
{
名称:“POD_订单数量”,
索引:“o.POD\U订单数量”,
是的,
对齐:'居中',
jsonmap:“cell.3”,
宽度:“100”
},
{
名称:“POD_QtyReceived”,
索引:“o.POD_QtyReceived”,
是的,
对齐:'居中',
jsonmap:“cell.4”,
宽度:“100”
},
{name:“POD_ItemNumID#”,index:“o.POD_ItemNumID”,可编辑:false,align:'center',jsonmap:'cell.5},
{
名称:“POD_VendorItemNum”,
索引:“o.POD_vendoritemum”,
可编辑:false,
对齐:'居中',
jsonmap:“cell.6”
},
{
名称:“POD_供应商定价”,
索引:“o.POD_供应商列表价格”,
是的,
对齐:'居中',
格式化程序:“货币”,
格式选项:{前缀:'$',后缀:'',千分位:','},
jsonmap:“cell.7”
},
{
名称:“POD_Vendordisont”,
索引:“o.POD_vendordisont”,
是的,
jsonmap:“cell.8”,
编辑选项:{
dataInit:函数(elem){
var$self=$(this),//保存对网格的引用
$elem=$(elem);//保存对的引用
$(元素)。自动完成({
来源:autocompleteSource,
选择:功能(事件、用户界面){
var$tr=$elem.closest(“tr.jqgrow”)、newCost、rowid=$tr.attr(“id”),
orderQty=parseFloat($tr.find(“输入[name=POD\u orderQty]”)val(),
listPrice=parseFloat($tr.find(“输入[name=POD\u VendorListPrice]”)val());
if(ui.item){
控制台日志(订单数量);
控制台日志(listPrice);
newCost=(1-parseFloat(ui.item.id))*listPrice;
$self.jqGrid(“setRowData”,rowid{
POD_单位成本:新成本,
POD_ExtCost:订单数量*新成本
});
}
},
最小长度:0,
明查斯:0,
自动填充:对,
必须匹配:
var rowData = $('#list').jqGrid('getRowData', rowid);
cont = rowData.POD_VendorListPrice;
console.log(cont);
rowData.POD_ExtCost = (1-ui.item.id)*cont;
dataInit: function(elem) {
    var $self = $(this), // save the reference to the grid
        $elem = $(elem); // save the reference to <input>
    $elem.autocomplete({
        source: autocompleteSource,
        select: function (event, ui) {
            var $tr = $elem.closest("tr.jqgrow"), newCost, rowid = $tr.attr("id"),
                orderQty = parseFloat($tr.find("input[name=POD_OrderQty]").val()),
                listPrice = parseFloat($tr.find("input[name=POD_VendorListPrice]").val());
            if (ui.item) {
                console.log(orderQty);
                console.log(listPrice);
                newCost = (1 - parseFloat(ui.item.id)) * listPrice;
                $self.jqGrid("setRowData", rowid, {
                    POD_UnitCost: newCost,
                    POD_ExtCost: orderQty * newCost
                });
            }
        },
        minLength: 0,
        minChars: 0,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 220
    }).on("focus", function(event) {
        $(this).autocomplete("search", "");
    });
}