gpt4 book ai didi

javascript - 如何在内联编辑中更新其他列更改的列

转载 作者:行者123 更新时间:2023-12-02 14:14:48 25 4
gpt4 key购买 nike

免费的 jqgrid 包含 3 列:价格、数量和总和。

使用html5数字输入类型。

如果在内联编辑中更改“总和”列,则应使用公式计算“价格”列值

Price = Sum / Quantity;

我尝试使用下面的 jqgrid 模板来实现此功能,但它不会更改价格列,因为 input#Priceinput#Quantity 未定义。

元素 ID 是根据行 ID 创建的,每行都不同。Jqgrid 不传递行 id 值来更改事件。

免费 jqgrid 中实现此类计算的最佳实践是什么?

var sumColumnTemplate = {
"editoptions": {
"type": "number",
"dataEvents":[{"type":"change","fn":function(e) {
$('input#Price').val(parseFloat(this.value) / parseFloat(
$('input#Quantity').val() ));
}
}
};

Chrome 检查元素显示,在内联编辑模式下为行创建了以下标记:

<tr role="row" id="1383" tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr" editable="1" aria-selected="false">
... lot of td s skipped

<td role="gridcell" style="text-align:right;" class="" title="4" aria-describedby="grid_Quantity"><input type="number" class="grid-decimal-edit editable" id="1383_Quantity" name="Quantity" cm="[object Object]" icol="5" role="textbox" style="width: 100%; box-sizing: border-box;"></td>

<td role="gridcell" style="text-align:right;" class=""
aria-describedby="grid_Price"><input type="number" title="" maxlength="15" class="grid-decimal-edit editable" id="1383_Price" name="Price" cm="[object Object]" icol="6" role="textbox" style="width: 100%; box-sizing: border-box;"></td>

<td role="gridcell" style="text-align:right;" title="" aria-describedby="grid_Sum"><input type="number" title="" maxlength="15" class="grid-decimal-edit editable" id="1383_Sum" name="Sum" cm="[object Object]" icol="7" role="textbox" style="width: 100%; box-sizing: border-box;"></td>
....
</tr>

表有很多行,id中的1383可能是行号,每行都不同。

在内联编辑模式下从当前行获取数值的最佳方法是什么?

使用 Bootstrap 3、jquery、jquery-ui、ASP.NET MVC 4、Razor View 、.NET 4.6。

更新

列定义:

{"label":"Quantity","name":"Quantity","index":"Quantity","searchoptions":{"sopt":["eq","ne","lt","le","gt","ge"],"maxlength":12,"size":12},"template":"number","formatoptions":{"thousandsSeparator":"","decimalPlaces":4,"defaultValue":""},"align":"right","editoptions":{"type":"number","step":"any","min":-999999,"max":9999999,"title":"","maxlength":12,"dataEvents":[{"type":"change","fn":function(e) {dataChanged(e.target)}
},{"type":"focus","fn":function(e) {if(typeof e.target.ischanged=='undefined') {e.target.ischanged=false}}
},{"type":"blur","fn":function(e) {}
}],"readonly":null,"class":"grid-decimal-edit","disabled":null},"editable":function(options){return getEditable(options,false);}
,"width":68,"classes":"","hidden":false},

{"label":"OstuPrice","name":"Price","index":"Price","searchoptions":{"sopt":["eq","ne","lt","le","gt","ge"],"maxlength":15,"size":15},"template":"number","formatoptions":{"thousandsSeparator":"","decimalPlaces":5,"defaultValue":""},"align":"right","editoptions":{"type":"number","step":"any","min":-99999999,"max":999999999,"title":"","maxlength":15,"dataEvents":[{"type":"change","fn":function(e) {dataChanged(e.target)}
},{"type":"focus","fn":function(e) {if(typeof e.target.ischanged=='undefined') {e.target.ischanged=false}}
},{"type":"blur","fn":function(e) {}
}],"readonly":null,"class":"grid-decimal-edit","disabled":null},"editable":function(options){return getEditable(options,false);}
,"width":75,"classes":"","hidden":false,"tere":"1234"},

{"template":sumColumnTemplate
,"label":"Sum","name":"Sum","width":80,"index":"Sum","hidden":false},

最佳答案

存在此问题是因为您使用 template 属性并将对象作为值。从 jqGrid 4.7 开始(请参阅 my old pull request ),可以定义“标准”模板并将其用作字符串。

需要使用如下代码来定义

$.jgrid = $.jgrid || {};
$.jgrid.cmTemplate = $.jgrid.cmTemplate || {};
$.jgrid.cmTemplate.mySum = {
editoptions: {
type: "number",
dataEvents: [{
type: "change",
fn: function(e) {
// some code
}
}]
}
};

现在可以使用模板:“mySum”:

{"template":"mySum","label":"Sum","name":"Sum","width":80}

而不是模板:sumColumnTemplate:

{"template":sumColumnTemplate,"label":"Sum","name":"Sum","width":80,
"index":"Sum","hidden":false}

关于javascript - 如何在内联编辑中更新其他列更改的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39130547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com