forked from angular-ui/ui-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
212 lines (205 loc) · 10.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/// <reference path="../plugins/ng-grid-reorderable.js" />
/// <reference path="../ng-grid-1.0.0.debug.js" />
function userController($scope) {
var self = this;
$scope.mySelections = [];
$scope.mySelections2 = [];
$scope.myData = [];
$scope.filterOptions = {
filterText: "",
useExternalFilter: false
};
$scope.pagingOptions = {
pageSizes: [250, 500, 1000], //page Sizes
pageSize: 250, //Size of Paging data
totalServerItems: 0, //how many items are on the server (for paging)
currentPage: 1 //what page they are currently on
};
var testData = [{ name: "Moroni", age: 50, id: 101 },
{ name: "Tiancum", age: 43, id: 102 },
{ name: "Jacob", age: 27, id: 103 },
{ name: "Nephi", age: 29, id: 104 },
{ name: "Enos", age: 34, id: 105 }];
self.getPagedDataAsync = function (pageSize, page, searchText) {
setTimeout(function () {
self.gettingData = true;
var data;
if (searchText) {
var ft = searchText.toLowerCase();
data = testData.filter(function (item) {
return JSON.stringify(item).toLowerCase().indexOf(ft) != -1;
});
} else {
data = testData;
}
var pagedData = data.slice((page - 1) * pageSize, page * pageSize);
$scope.pagingOptions.totalServerItems = data.length;
$scope.myData = pagedData;
if (!$scope.$$phase) {
$scope.$apply();
}
self.gettingData = false;
}, 100);
};
$scope.$watch('pagingOptions', function () {
if (!self.poInit || self.gettingData) {
self.poInit = true;
return;
}
self.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}, true);
$scope.$watch('filterOptions', function () {
if (!self.foInit || self.gettingData) {
self.foInit = true;
return;
}
self.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}, true);
self.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);
$scope.myDefs = [
{ field: 'name', displayName: 'Very Long Name Title', width: 300 },
{ field: 'allowance', aggLabelFilter: 'currency', width: 300 },
{ field: 'birthday', cellFilter: "date:'yyyy-MM-dd HH:mm:ss'", width: 300 },
{ field: 'paid', cellFilter: 'checkmark', width: 300 },
{ field: 'sdaf', displayName: 'sadfasdfasdfasd', headerClass: 'foo', width: 300 },
{ field: 'asdf', aggLabelFilter: 'currency', width: 300 },
{ field: 'asdgasg', cellFilter: 'date', resizable: false, width: 300 },
{ field: 'asgdasga', cellFilter: 'checkmark', width: 300 },
{ field: 'asgasgadf', displayName: 'asgasgadf', headerClass: 'foo', width: 300 },
{ field: 'asdgasgasgagsd', aggLabelFilter: 'currency', width: 300 },
{ field: 'asdasdgasdg', cellFilter: 'date', width: 300 },
{ field: 'sadfasdfasdfasd', cellFilter: 'checkmark', width: 300 }];
var myplugin = {
init: function(scope, grid) {
myplugin.scope = scope;
myplugin.grid = grid;
$scope.$watch(function () {
var searchQuery = "";
angular.forEach(myplugin.scope.columns, function (col) {
if (col.filterText) {
searchQuery += col.field + ": " + col.filterText + "; ";
}
});
return searchQuery;
}, function (searchQuery) {
myplugin.scope.$parent.filterText = searchQuery;
myplugin.grid.searchProvider.evalFilter();
});
},
scope: undefined,
grid: undefined
};
$scope.myDefs2 = [{ field: 'Sku', displayName: 'My Sku', enableCellEdit: true },
{ field: 'Vendor', displayName: 'Supplier', enableCellEdit: true },
{ field: 'SeasonCode', displayName: 'My SeasonCode', enableCellEdit: true },
{ field: 'Mfg_Id', displayName: 'Manufacturer ID', enableCellEdit: true },
{ field: 'UPC', displayName: 'Bar Code', enableCellEdit: true }];
self.selectionchanging = function (a, b) {
return true;
};
$scope.gridOptions = {
data: 'myData',
enableColumnResize: true,
enableColumnReordering: true,
selectedItems: $scope.mySelections,
headerRowHeight: 40,
pagingOptions: $scope.pagingOptions,
enablePaging: true,
enableRowSelection: true,
multiSelect: false,
enableRowReordering: false,
enablePinning: true,
showGroupPanel: true,
showFooter: false,
showFilter: true,
enableCellEdit: true,
enableCellSelection: true,
showColumnMenu: true,
maintainColumnRatios: true,
columnDefs: 'myDefs',
primaryKey: 'id',
sortInfo: {fields:['name'], directions:['asc'] }
};
$scope.doStuff = function (evt) {
var elm = angular.element(evt.currentTarget.parentNode);
elm.on('change', function() {
var scope = elm.scope();
scope.$parent.isFocused = false;
});
};
$scope.myData2 = [{ 'Sku': 'C-2820164', 'Vendor': 'NEWB', 'SeasonCode': null, 'Mfg_Id': '573-9880954', 'UPC': '822860449228' },
{ 'Sku': 'J-8555462', 'Vendor': 'NIKE', 'SeasonCode': '', 'Mfg_Id': '780-8855467', 'UPC': '043208523549' },
{ 'Sku': 'K-5312708', 'Vendor': 'REEB', 'SeasonCode': '1293', 'Mfg_Id': '355-6906843', 'UPC': '229487568922' },
{ 'Sku': 'W-4295255', 'Vendor': 'REEB', 'SeasonCode': '6283', 'Mfg_Id': '861-4929378', 'UPC': '644134774391' },
{ 'Sku': 'X-9829445', 'Vendor': 'DOCK', 'SeasonCode': '6670', 'Mfg_Id': '298-5235913', 'UPC': '872941679110' },
{ 'Sku': 'H-2415929', 'Vendor': 'REEB', 'SeasonCode': '3884', 'Mfg_Id': '615-8231520', 'UPC': '310547300561' },
{ 'Sku': 'X-2718366', 'Vendor': 'MERR', 'SeasonCode': '4054', 'Mfg_Id': '920-2961971', 'UPC': '157891269493' },
{ 'Sku': 'Q-1505237', 'Vendor': 'AX', 'SeasonCode': '9145', 'Mfg_Id': '371-6918101', 'UPC': '553657492213' },
{ 'Sku': 'M-1626429', 'Vendor': 'REEB', 'SeasonCode': '1846', 'Mfg_Id': '242-5856618', 'UPC': '029388467459' },
{ 'Sku': 'Y-1914652', 'Vendor': 'LEVI', 'SeasonCode': '5553', 'Mfg_Id': '80-9194110', 'UPC': '433360049369' }];
$scope.gridOptions2 = {
data: 'myData2',
selectedItems: $scope.mySelections2,
beforeSelectionChange: self.selectionchanging,
showFilter: true,
multiSelect: true,
columnDefs: 'myDefs2',
enablePinning: true,
groupsCollapsedByDefault: false
};
$scope.changeData = function () {
$scope.myData2.pop();
};
$scope.changeLang = function () {
$scope.gridOptions.i18n = 'ge';
};
$scope.spliceData = function () {
var temp = $scope.myData2;
temp.splice(0, 0, { 'Sku': 'Y-1914652', 'Vendor': 'LEVI', 'SeasonCode': '5553', 'Mfg_Id': '80-9194110', 'UPC': '433360049369' });
$scope.myData2 = temp;
};
$scope.resetData = function () {
$scope.myData2 = [{ 'Sku': 'C-2820164', 'Vendor': 'NEWB', 'SeasonCode': null, 'Mfg_Id': '573-9880954', 'UPC': '822860449228' },
{ 'Sku': 'J-8555462', 'Vendor': 'NIKE', 'SeasonCode': '', 'Mfg_Id': '780-8855467', 'UPC': '043208523549' },
{ 'Sku': 'K-5312708', 'Vendor': 'REEB', 'SeasonCode': '1293', 'Mfg_Id': '355-6906843', 'UPC': '229487568922' },
{ 'Sku': 'W-4295255', 'Vendor': 'REEB', 'SeasonCode': '6283', 'Mfg_Id': '861-4929378', 'UPC': '644134774391' },
{ 'Sku': 'X-9829445', 'Vendor': 'DOCK', 'SeasonCode': '6670', 'Mfg_Id': '298-5235913', 'UPC': '872941679110' },
{ 'Sku': 'H-2415929', 'Vendor': 'REEB', 'SeasonCode': '3884', 'Mfg_Id': '615-8231520', 'UPC': '310547300561' },
{ 'Sku': 'X-2718366', 'Vendor': 'MERR', 'SeasonCode': '4054', 'Mfg_Id': '920-2961971', 'UPC': '157891269493' },
{ 'Sku': 'Q-1505237', 'Vendor': 'AX', 'SeasonCode': '9145', 'Mfg_Id': '371-6918101', 'UPC': '553657492213' },
{ 'Sku': 'M-1626429', 'Vendor': 'REEB', 'SeasonCode': '1846', 'Mfg_Id': '242-5856618', 'UPC': '029388467459' },
{ 'Sku': 'Y-1914652', 'Vendor': 'LEVI', 'SeasonCode': '5553', 'Mfg_Id': '80-9194110', 'UPC': '433360049369' }];;
};
$scope.modifyData = function(){
$scope.myData2[0].Vendor = "HELLO";
};
$scope.myData3 = [{ 'Sku': 'C-2820164', 'Vendor': {'name':'NIKE'}, 'SeasonCode': null, 'Mfg_Id': '573-9880954', 'UPC': '822860449228' },
{ 'Sku': 'J-8555462', 'Vendor': {'name':'NIKE'}, 'SeasonCode': '', 'Mfg_Id': '780-8855467', 'UPC': '043208523549' },
{ 'Sku': 'K-5312708', 'Vendor': {'name':'NIKE'}, 'SeasonCode': '1293', 'Mfg_Id': '355-6906843', 'UPC': '229487568922' },
{ 'Sku': 'W-4295255', 'Vendor': {'name':'NIKE'}, 'SeasonCode': '6283', 'Mfg_Id': '861-4929378', 'UPC': '644134774391' },
{ 'Sku': 'X-9829445', 'Vendor': {'name':'NIKE'}, 'SeasonCode': '6670', 'Mfg_Id': '298-5235913', 'UPC': '872941679110' },
{ 'Sku': 'H-2415929', 'Vendor': {'name':'REEB'}, 'SeasonCode': '3884', 'Mfg_Id': '615-8231520', 'UPC': '310547300561' },
{ 'Sku': 'X-2718366', 'Vendor': {'name':'REEB'}, 'SeasonCode': '4054', 'Mfg_Id': '920-2961971', 'UPC': '157891269493' },
{ 'Sku': 'Q-1505237', 'Vendor': {'name':'REEB'}, 'SeasonCode': '9145', 'Mfg_Id': '371-6918101', 'UPC': '553657492213' },
{ 'Sku': 'M-1626429', 'Vendor': {'name':'REEB'}, 'SeasonCode': '1846', 'Mfg_Id': '242-5856618', 'UPC': '029388467459' },
{ 'Sku': 'Y-1914652', 'Vendor': {'name':'REEB'}, 'SeasonCode': '5553', 'Mfg_Id': '80-9194110', 'UPC': '433360049369' }];
$scope.myDefs3 = [{ field: 'Sku', displayName: 'My Sku' },
{ field: 'Vendor.name', displayName: 'Supplier', cellFilter: 'branding' },
{ field: 'SeasonCode', displayName: 'My SeasonCode', cellTemplate: '<input style="width:100%;height:100%;" class="ui-widget input" type="text" ng-readonly="!row.selected" ng-model="row.entity[col.field]"/>' },
{ field: 'Mfg_Id', displayName: 'Manufacturer ID' },
{ field: 'UPC', displayName: 'Bar Code' }];
$scope.filteringText = '';
$scope.gridOptions3 = {
data: 'myData3',
multiSelect: false,
filterOptions: {filterText:'filteringText', useExternalFilter: false},
columnDefs: 'myDefs3'
};
$scope.$on('filterChanged', function(evt, text){
$scope.filteringText = text;
});
$scope.setSelection = function() {
$scope.gridOptions2.selectRow(0, true);
};
$scope.dropDownOpts = ['editing', 'is', 'impossibru?'];
};