简体   繁体   中英

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:

 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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