在选择复选框时获取kendo网格行数据

时间:2014-09-03 08:01:35

标签: kendo-ui kendo-grid kendo-dataviz

我正在尝试使用复选框获取选择特定行的kendo数据。

这是controller.js

的代码的一部分
$scope.campaignLabelOptions = {
            dataSource: {
                data: [] ,
            },

            sortable: true,
            pageable : {pageSizes : [5, 10, 25, 50]},
            filterable : true,
            resizable  :true,
            reordable :true,
            scrollable:true,
            columnMenu: true,
            selectable :true,
            editable: {
                confirmation: "Are you sure that you want to delete this record?",
                mode: "popup"
            }, 
            columns : [
                  {template: "<input type='checkbox' class='checkbox' ng-click='onClick($event)'/>" },
                  {field : "campaign_name", title :"Campaign Name", width : "150px", attributes: {style: "font-size: 12px"}},
                  // {field : "time_line", title :"Timeline", width : "100px",attributes: {style: "font-size: 12px"} },
                  {field : "spend", title :"Spend", width : "90px",attributes: {style: "font-size: 12px"} },
                  {field : "campaign_group_status", title :"Status", width : "85px", attributes: {style: "font-size: 12px"}},
                  {field : "performance", title :"Performance", width : "130px", attributes: {style: "font-size: 12px"}},
                  // {field : "creation_time", title :"Created Time", width : "135px", attributes: {style: "font-size: 12px"}},                
                  ],
        }; 




$scope.checkedIds = [];
        $scope.showCheckboxes = function(){
          var checked = [];
          for(var i in $scope.checkedIds){
            if($scope.checkedIds[i]){
              checked.push(i);
            }
          }
          alert(checked);
        };

        $scope.onClick = function(e){
          console.log(e);
          var element =$(e.currentTarget);

          var checked = element.is(':checked'); 
          var row = element.closest("tr"); 
          var grid = element.closest('kendoGrid').getKendoGrid(); 
          var dataItem = grid.dataItem(row);

          $scope.checkedIds[dataItem.EmployeeID] = checked;
          if (checked) {
            row.addClass("k-state-selected");
          } else {
            row.removeClass("k-state-selected");
          }
        };

我已经从http://dojo.telerik.com/exAB/5复制了类似的代码用于选择逻辑。但是这里的网格变量未定义。它没有得到getKendoGrid()方法..

有没有更好的方法来获取行数据?如果是,那么如何使用 - 如何使用当前代码?

0 个答案:

没有答案