简体   繁体   中英

How do i get hidden value from Kendo grid with onSave event

i have a edit button and in Kendo grid onSave event that will fire up when i change something in a row. Now i want to access dataItem values when i update row but for some reason it's always null, what am i doing wrong? I have no problems accessing value in drop down menu tho but i also need hidden values.

JS

function onSave(e) {
        if (e.model.StatusIdD) {     
            e.model.StatusIdD = 0;
            var currentlySelectedValue = $(e.container).find('#StatusIdD').data("kendoDropDownList").value();
            var dataItem = this.dataItem($(e.target).closest("tr"));
            var bojaTeksta = dataItem.BojaTeksta;
            console.log(bojaTeksta);
            e.model.set('StatusIdD', currentlySelectedValue);
            e.model.set('Status', $(e.container).find('#StatusIdD').data("kendoDropDownList").text());
            //e.model.set('BojaPozadine', currentlySelectedValue);
            //e.model.set('BojaTeksta', currentlySelectedValue);
        }     
    }

Grid - simplified

...
columns.Bound(p => p.BojaTeksta).Hidden(true);
columns.Bound(p => p.BojaPozadine).Hidden(true);
...
.Events(e => e.Remove("onRemove").Save("onSave"))

ANSWER

i managed to get data with selectedItem rather then dataItem (when you click a command button you automatically select a row)

var grid = $("#Grid" + '@guid').data("kendoGrid"); 
var selectedItem = grid.dataItem(grid.select()); 
var bojaTeksta = selectedItem.BojaTeksta; 
var bojaPozadine = selectedItem.BojaPozadine; 
console.log(bojaTeksta); 
console.log(bojaPozadine);

You should not have any trouble getting hold of a hidden value.

First make sure the BojaTeksta is set. By inspecting the generated html.

It should look something like:

<td role="gridcell" style="display:none">123</td>

Check to see if you are getting other values from your dataItem. Values that are not hidden.

If not try using the currentTarget instead of target on the event:

var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

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