简体   繁体   English

Kendo Grid:如何更改模板中的字段值?

[英]Kendo Grid: How to change a field value in a template?

I'm using a kendo grid to display current values from a data source. 我正在使用剑道网格来显示数据源中的当前值。 Within the Kendo grid buttons are created to alter the values and display the change: 在Kendo网格内创建按钮以更改值并显示更改:

 var grid = $("#Results").kendoGrid({ dataSource: resultsDS, columns: [{ title: "Drop Hammer", field: "drop_hammer_bit", width: 125, filterable: false, template: "<button type='button' class='btn pass-fail-btn' onclick='yes_btn_toggle($(this))'>#= drop_hammer_bit #</button>" }] }).data('kendoGrid'); function yes_btn_toggle(e) { var txt = $(e).html(); if (txt == "No") { $(e).removeClass('btn-secondary').addClass('btn-primary'); $(e).html("Yes"); $(e).value = "Yes"; } else { $(e).removeClass('btn-primary').addClass('btn-secondary'); $(e).html("No"); } } 

There is a submit button which retrieves the Results data but it reflects data source and not the changes. 有一个提交按钮,它检索结果数据,但它反映的是数据源,而不是更改。 I am struggling on understanding how to either A) correctly code the button click so that the submitted values are correctly or B) change how I can retrieve the altered data. 我正在努力理解如何A)正确编码按钮单击,以便正确提交提交的值,或B)改变我如何检索更改后的数据。 So far my Submission function is this: 到目前为止,我的提交功能是这样的:

 function submitQuality() { var data = $("#Results").data(); var displayedData = $("#Results").data().kendoGrid.dataSource.view(); var cntr = displayedData.length; var BatchQuality = new Array(); for (var i = 0; i < cntr; i++) { var qualityObj = buildQuality(displayedData[i]); BatchQuality.push(qualityObj); } } 

Ultimately what I want to do is display the data source values of Yes/No and give the user the option to click a button to change its value. 最终,我要显示的是“是/否”数据源值,并为用户提供单击按钮以更改其值的选项。 When they are ready they would click the Submit button to record the new changes. 准备就绪后,他们将单击“提交”按钮以记录新更改。 I feel like I am close to the answer but I lack the proper programming knowledge to weave it all syntactically. 我觉得自己已经很接近答案了,但是我缺乏适当的编程知识来语法化地组织它们。

I am not sure your requirement but i guess you are wondering to changed value yes to no and no to yes from kendo grid column button. 我不确定您的要求,但我想您想将Kendo网格列按钮的值更改为“是”和“否”。

You will have to use refresh grid after changed value in the datasource. 在数据源中更改值后,您将必须使用刷新网格。

 $('#Results').data('kendoGrid').refresh()

Please let me know if code work for your. 请让我知道代码是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM