如何在Kendo UI Grid中获取复选框的值?

时间:2013-07-09 05:57:17

标签: checkbox kendo-grid

所以我搜索了许多答案,似乎无法找到任何具体内容......所以这里就是..

我有一个标准的Kendo UI网格 - 我按如下方式设置了一个列:

{   title: "Sharing Enabled?", 
    field: "permissions_users_apps_user_sharing", 
    attributes: {
        style: "text-align: center; font-size: 14px;"
    },
    filterable: true,
    headerAttributes: {
        style: "font-weight: bold; font-size: 14px; width: 40px;"
    },
    template: function(dataItem) {
        if ( dataItem.permissions_users_apps_user_sharing == 0 ) {
            return "<input type='checkbox' name='permissions_users_apps_status' id='permissions_users_apps_status' value='1' />"
        } else if ( dataItem.permissions_users_apps_user_sharing == 1 ) {
            return "<input type='checkbox' name='permissions_users_apps_status' id='permissions_users_apps_status' value='1' checked />"
        }
    }
},

当我单击我定义的COMMAND按钮时,我要做的是获取此复选框的值(以查看它是否已更改)。 ROW是可选择的..所以我可以得到行的ID。但我似乎无法收集复选框的价值。

有人有建议吗?

提前致谢..

2 个答案:

答案 0 :(得分:2)

当复选框状态发生变化时,您可以在dataBound事件中获取复选框的实例。 看看以下代码是否对您有所帮助。

 ....
 columns: [
 {
  { field: "select", template: '<input id="${BindedColumn}" onclick="GrabValue(this)" type="checkbox"/>', width: "35px", title: "Select" },
 }
 ....
 selectable: "multiple, row",
 dataBound: function () {
            var grid = this;
            //handle checkbox change
            grid.table.find("tr").find("td:nth-child(1) input")
            .change(function (e) {
                var checkbox = $(this);
                //Write code to get checkbox properties for all checkboxes in grid
                var selected = grid.table.find("tr").find("td:nth-child(1) input:checked").closest("tr");

                //Write code to get selected checkbox properties
                ......
                //Code below to clear grid selection
                grid.clearSelection();
                //Code below to select a grid row based on checkbox selection 
                if (selected.length) {
                    grid.select(selected);
                }
            })
        }
        .....
        function GrabValue(e)
        {
         //Alert the checkbox value
         alert(e.value);
         //get the grid instance
         var grid = $(e).closest(".k-grid").data("kendoGrid");
         //get the selected row data
         var dataItem = grid.dataSource.view()[grid.select().closest("tr").index()];
         }

答案 1 :(得分:0)

使用此方法可以获得选中的复选框值。

    10-27 13:45:52.615  13986-13986/com.pfe.neighborhoodserviceslbs
    E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.pfe.neighborhoodserviceslbs, PID: 13986
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pfe.neighborhoodserviceslbs/com.pfe.neighborhoodserviceslbs.MainActivity}: java.lang.IllegalArgumentException: invalid provider: null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.IllegalArgumentException: invalid provider: null
        at android.location.LocationManager.checkProvider(LocationManager.java:1704)
        at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1194)
        at com.pfe.neighborhoodserviceslbs.MainActivity.onCreate(MainActivity.java:129)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

了解更多详情Goto