custom row template in ng-grid angularjs

custom row template in ng-grid angularjs

The HTML code-sample for ng-grid
?
1
2
3
4
5
6
7
<fieldset ng-app="ngGridApp" >
      <legend>
      </legend>
    <div ng-controller="ngGridController" >
      <div class="ngGridStyle" ng-grid="ngGridView"></div>
    </div>
</fieldset>
 <fieldset ng-app="ngGridApp" >
      <legend>
      </legend>
    <div ng-controller="ngGridController" >
      <div class="ngGridStyle" ng-grid="ngGridView"></div>
    </div>
</fieldset> 
The Custom row Template code-sample
?
1
2
var removeRowTemplate = '<span style="display:block; text-align:center;"><button ng-click="editRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i></button><button ng-click="removeRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-times"></i></button></span>';
var onoffTemplate = '<span class="smart-form"><label class="toggle"><input type="checkbox" checked="checked" name="checkbox-toggle"><i data-swchoff-text="OFF" data-swchon-text="ON"></i></label></span>';
var removeRowTemplate = '<span style="display:block; text-align:center;"><button ng-click="editRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i></button><button ng-click="removeRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-times"></i></button></span>';
var onoffTemplate = '<span class="smart-form"><label class="toggle"><input type="checkbox" checked="checked" name="checkbox-toggle"><i data-swchoff-text="OFF" data-swchon-text="ON"></i></label></span>';
The create and use of custom row template in ng-grid code-sample
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var app = angular.module('ngGridApp', ['ngGrid']);
app.controller('ngGridController', function ($scope) {
    $scope.ACPreferences = [{
        Nominees: "Anil Singh",
        Email: '[email protected]',
        Threshold: '50%, 70%, 80%, 85%, 90%, 100%,120%',
        SendSMS: true,
        SendEmail: true,
        AlertOptIn: true   
    }];
    $scope.filterOptions = {
        filterText: ''
    };
    $scope.pagingOptions = {
        pageSizes: [10, 20, 50, 100],
        pageSize: 10,
        totalServerItems: 0,
        currentPage: 1
    };
    var removeRowTemplate = '<span style="display:block; text-align:center;"><button ng-click="editRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i></button><button ng-click="removeRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-times"></i></button></span>';
    var onoffTemplate = '<span class="smart-form"><label class="toggle"><input type="checkbox" checked="checked" name="checkbox-toggle"><i data-swchoff-text="OFF" data-swchon-text="ON"></i></label></span>';
    $scope.myColumns = [{ field: 'Nominees', displayName: 'Nominees' },
            { field: 'Email', displayName: 'Email', editableCellTemplate: true, enableCellEdit: true },
            { field: 'Threshold', displayName: 'Threshold' },
            { field: 'SendSMS', displayName: 'Send SMS', width: "7%" },
            { field: 'SendEmail', displayName: 'Send Email', width: "8%" },
            { field: 'AlertOptIn', displayName: 'Alert Opt-In', width: "9%", cellTemplate: onoffTemplate },
            { field: 'remove', displayName: '', width: "7%", cellTemplate: removeRowTemplate } ];
    $scope.ngGridView = {
        data: 'ACPreferences',
        enablePaging: true,
        showFooter: true,
        filterOptions: $scope.filterOptions,
        pagingOptions: $scope.pagingOptions,
        columnDefs: 'myColumns'
    };
});
var app = angular.module('ngGridApp', ['ngGrid']);
app.controller('ngGridController', function ($scope) {
    $scope.ACPreferences = [{
        Nominees: "Anil Singh",
        Email: '[email protected]',
        Threshold: '50%, 70%, 80%, 85%, 90%, 100%,120%',
        SendSMS: true,
        SendEmail: true,
        AlertOptIn: true    
    }];

    $scope.filterOptions = {
        filterText: ''
    };

    $scope.pagingOptions = {
        pageSizes: [10, 20, 50, 100],
        pageSize: 10,
        totalServerItems: 0,
        currentPage: 1
    };

    var removeRowTemplate = '<span style="display:block; text-align:center;"><button ng-click="editRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i></button><button ng-click="removeRowIndex($index)" class="btn btn-xs btn-default"><i class="fa fa-times"></i></button></span>';
    var onoffTemplate = '<span class="smart-form"><label class="toggle"><input type="checkbox" checked="checked" name="checkbox-toggle"><i data-swchoff-text="OFF" data-swchon-text="ON"></i></label></span>';

    $scope.myColumns = [{ field: 'Nominees', displayName: 'Nominees' },
            { field: 'Email', displayName: 'Email', editableCellTemplate: true, enableCellEdit: true },
            { field: 'Threshold', displayName: 'Threshold' },
            { field: 'SendSMS', displayName: 'Send SMS', width: "7%" },
            { field: 'SendEmail', displayName: 'Send Email', width: "8%" },
            { field: 'AlertOptIn', displayName: 'Alert Opt-In', width: "9%", cellTemplate: onoffTemplate },
            { field: 'remove', displayName: '', width: "7%", cellTemplate: removeRowTemplate } ];

    $scope.ngGridView = {
        data: 'ACPreferences',
        enablePaging: true,
        showFooter: true,
        filterOptions: $scope.filterOptions,
        pagingOptions: $scope.pagingOptions,
        columnDefs: 'myColumns'
    };
});
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.