简体   繁体   中英

How to pass variable from kendo grid to template function

I have a kendo grid as :

    $("#myGrid").kendoGrid({
    dataSource: dataSource,
    pageable: false,
    height: 350,
    columns: [
    { field: "Status", title: "Status", width: "130px", template: Getvalue("/#=Status#") },
    ],
    editable: false
});

and my function is:

    function Getvalue(Status) {
    if (Status == "Detected")
        return "11";
    }

The function gets called and it works. but I couldn't pass value of Status to function. I tried different things including /#=Status# but it doesn't work. any idea?

I managed to handle my problem. I found out that my problem comes from this point that I try to send value which hasn't been databounded yet. So there isn't any value to transfer to other function. What I did was defining inline function inside filed and handling all needed changes by function. So my code now is:

$("#LoggerAttachingLogGrid").kendoGrid({
    dataSource: mydata,
    pageable: false,
    height: 350,
    columns: [
    { field: "Status", title: "Status", width: "130px", template:
            function (data, type, full, meta) {
            return data.Status == "Detected" ? '<span class="LoggerDetected"><i class="fa fa-bolt"></i> Detected</span>' :
            data.Status == "Configuring" ? '<span class="LoggerConfiguring"><i class="fa fa-spinner fa-pulse"></i> Configuring</span>' :
            data.Status == "Configured and attached" ? '<span class="LoggerTick"><i class="fa fa-check"></i> Successful</span><br />' :
            data.Status == "Error" ? '<span class="LoggerError"><i class="fa fa-times"></i> Error, see alert above</span>' :
            data.Status
            }
    }
    ],

    editable: false
});

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