【问题标题】:how to get the selected checkbox values in cell of ui-grid using angularjs如何使用angularjs在ui-grid的单元格中获取选定的复选框值
【发布时间】:2016-05-05 14:06:45
【问题描述】:

我有UI-grid 构建在angularjs 中,我在哪个单元格模板中使用了复选框。当我单击特定复选框时,我想获取该复选框值,这意味着我有类似表格的结构,并且在表格单元格中我有复选框。现在我想获取选中的复选框值。

这是我的代码

$scope.gridOptionsNew = {
appScopeProvider : $scope,
columnDefs : [{
        enableCellEdit : false,
        field : 'SponsorType',
        displayName : me.labelText.ADD_STORY_TABLE_SPONSOR_TYPE

    }, {
        //enableCellEdit: true,
        field : 'Hoarding',
        displayName : me.labelText.ADD_STORY_TABLE_HOARDING,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    },
    {
        //enableCellEdit: true,
        field : 'Print',
        displayName : me.labelText.ADD_STORY_TABLE_PRINT,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'Radio',
        displayName : me.labelText.ADD_STORY_TABLE_RADIO,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'StageBackDrops',
        displayName : me.labelText.ADD_STORY_TABLE_STAGE_BACK_DROP,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'Stalls',
        displayName : me.labelText.ADD_STORY_TABLE_STALLS,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'Banners',
        displayName : me.labelText.ADD_STORY_TABLE_BANNERS,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'Seats',
        displayName : me.labelText.ADD_STORY_SEATS,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'VenueBanners',
        displayName : me.labelText.ADD_STORY_VENUE_BRANDING,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }, {
        //enableCellEdit: true,
        field : 'StagePresence',
        displayName : me.labelText.ADD_STORY_STAGE_PRESENCE,
        cellTemplate : '<div class="text-center"><input type="checkbox" ' +
        'name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    }
]}

$scope.yourMethod = function (radio) {
  console.log("value", radio);
};

【问题讨论】:

    标签: angularjs gridview angular-ui-grid checkboxlist


    【解决方案1】:

    请尝试如下所示。

    设置网格选项,例如:

     $scope.gridOptionsNew = { 
             appScopeProvider: $scope,
             //your other options
    

    然后是模板:

    cellTemplate: '<div class="text-center"><input type="checkbox" '+
    name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity.Radio)"/></div>'
    

    方法:

         //your Method
          $scope.yourMethod = function (radio) {
    
            //your logic
          };
    

    更新:

    cellTemplate: '<div class="text-center"><input type="checkbox" '+
    name="radio" value="radio" ng-click="grid.appScope.yourMethod(row.entity)"/></div>'
    

    【讨论】:

    • 您好,非常感谢您的回答。我只是在函数中控制台了 radio 的值,但显示未定义。我做了这个 $scope.yourMethod = function (radio) { console.log("hello",radio); };它在你好前面显示“”
    • 你能把你最新的代码sn-ps放在你上面的帖子里吗?
    • 请参阅Update 部分。尝试这样并使用调试查看值。只需使用F10 进行调试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多