1

I am using ui-grid for testing purpose. I added a checkbox on each row and a select on header.

HTML

<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="http://ui-grid.info/release/ui-grid.js"></script>
    <script src="main.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
  </head>
  <body>

    <div ng-controller="MainCtrl">
      <div ui-grid="gridOptions" class="grid"></div>
    </div>

  </body>
</html>

JS

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']);

app.controller('MainCtrl', ['$scope', 'uiGridConstants', function ($scope, uiGridConstants) {
  $scope.gridOptions = {
  enableFiltering: true,
  columnDefs: [
      {
        name: 'Items',
        filter: {
          type: uiGridConstants.filter.SELECT,
          selectOptions: [
            {value: '0', label: 'Unselect'},
            {value: '1', label: 'Selected'}
          ]
        },
        cellTemplate: '<input type="checkbox" name="select_item"/>'
      },
      {
        name: 'Name',
        field: 'name'
      },
      {
        name: 'Age',
        field: 'age'
      }
    ]
  };

  $scope.gridOptions.data = [
    { name: 'User 1', age: 20},
    { name: 'User 2', age: 30},
    { name: 'User 3', age: 40}
  ];
}]);

And this is the result

enter image description here

So how can I filter items by checked/uncheck checkbox? I only want to see all checked or unchecked items using filter.

0

1 Answer 1

1

I added the attribute selected to your data in order to be able to filter using the checkbox. You can delete it if you want to send data to the server. modifications:

template:

  `cellTemplate: '<input type="checkbox" name="select_item" value="true" ng-model="row.entity.selected"/>`'

data:

  $scope.gridOptions.data = [
    { name: 'User 1', age: 20,selected:false},
    { name: 'User 2', age: 30,selected:false},
    { name: 'User 3', age: 40,selected:false}
  ];

here is a plunnker: pluncker

But,I recommand to use the selector of the ui-grid: tutorial of ui-grid selector

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.