Skip to content

Commit b397966

Browse files
committed
transform to cover moving columns
1 parent 2338a85 commit b397966

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

dist/ui-scroll-grid.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-23T19:02:24.849Z
4+
* Version: 1.4.1 -- 2016-05-24T16:17:58.257Z
55
* License: MIT
66
*/
77

@@ -125,15 +125,32 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
125125

126126
$timeout(function () {
127127
scrollViewport.adapter.gridAdapter = new GridAdapter(_this);
128-
scrollViewport.adapter.transform = function (item) {
129-
return transform(item);
128+
scrollViewport.adapter.transform = function (scope, item) {
129+
return _this.transform(scope, item);
130130
};
131131
});
132132

133-
function transform(item) {
134-
console.log(item);
135-
console.log(rowMap.size);
136-
}
133+
this.transform = function (scope, item) {
134+
var _this2 = this;
135+
136+
var row = rowMap.get(scope);
137+
var parent = row[0].parent();
138+
var last = row[row.length - 1].next();
139+
var visible = [];
140+
columns.forEach(function (column, index) {
141+
_this2.applyCss(row[index], column.layout.css);
142+
visible[columns[index].mapTo] = row[index];
143+
});
144+
var current = visible.shift();
145+
current.detach();
146+
if (last.length) last.before(current);else parent.append(current);
147+
148+
visible.forEach(function (cell) {
149+
cell.detach();
150+
current.after(cell);
151+
current = cell;
152+
});
153+
};
137154

138155
this.registerColumn = function (header) {
139156
columns.push(new ColumnController(columns, header));
@@ -152,13 +169,14 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
152169
}
153170
if (index < columns.length) {
154171
columns[index].cells.push(cell);
172+
155173
var row = rowMap.get(scope);
156174
if (!row) {
157175
row = [];
158176
rowMap.set(scope, row);
159177
}
160178
row[index] = cell;
161-
this.applyCss(cell, columns[index].layout.css);
179+
162180
return index++;
163181
}
164182
return -1;
@@ -175,13 +193,13 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
175193
};
176194

177195
this.getColumns = function () {
178-
var _this2 = this;
196+
var _this3 = this;
179197

180198
var result = [];
181199
columns.slice().sort(function (a, b) {
182200
return a.mapTo - b.mapTo;
183201
}).forEach(function (column) {
184-
return result.push(new ColumnAdapter(_this2, column));
202+
return result.push(new ColumnAdapter(_this3, column));
185203
});
186204
return result;
187205
};
@@ -199,16 +217,16 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
199217
};
200218

201219
this.applyLayout = function (columnDescriptors) {
202-
var _this3 = this;
220+
var _this4 = this;
203221

204222
if (!columnDescriptors || !columnDescriptors.length) {
205223
return console.warn('Nothing to apply.');
206224
}
207225
columnDescriptors.forEach(function (columnDescriptor, index) {
208226
if (index < 0 || index >= columns.length) return;
209-
var columnAdapter = new ColumnAdapter(_this3, columns[index]);
227+
var columnAdapter = new ColumnAdapter(_this4, columns[index]);
210228
columns[index].reset();
211-
_this3.applyCss(columnAdapter, columnDescriptor.layout.css);
229+
_this4.applyCss(columnAdapter, columnDescriptor.layout.css);
212230
});
213231
};
214232

dist/ui-scroll-jqlite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-23T19:02:24.849Z
4+
* Version: 1.4.1 -- 2016-05-24T16:17:58.257Z
55
* License: MIT
66
*/
77

dist/ui-scroll.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-23T19:02:24.849Z
4+
* Version: 1.4.1 -- 2016-05-24T16:17:58.257Z
55
* License: MIT
66
*/
77

@@ -700,11 +700,11 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
700700
var sibling = insertAfter > 0 ? buffer[insertAfter - 1].element : undefined;
701701
linker(function (clone, scope) {
702702
promises = insertElement(clone, sibling);
703-
if (adapter.transform) adapter.transform(clone);
704703
wrapper.element = clone;
705704
wrapper.scope = scope;
706705
scope[itemName] = wrapper.item;
707706
});
707+
if (adapter.transform) adapter.transform(wrapper.scope, wrapper.element);
708708
return promises;
709709
}
710710

src/ui-scroll-grid.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,27 @@ angular.module('ui.scroll.grid', [])
103103

104104
this.transform = function (scope, item) {
105105
let row = rowMap.get(scope);
106+
let parent = row[0].parent();
107+
let last = row[row.length-1].next();
108+
let visible = [];
106109
columns.forEach((column, index) => {
107110
this.applyCss(row[index], column.layout.css);
108-
})
111+
visible[columns[index].mapTo] = row[index];
112+
});
113+
let current = visible.shift();
114+
current.detach();
115+
if (last.length)
116+
last.before(current);
117+
else
118+
parent.append(current);
119+
120+
visible.forEach((cell) => {
121+
cell.detach();
122+
current.after(cell);
123+
current = cell;
124+
});
125+
126+
109127
}
110128

111129
this.registerColumn = function (header) {
@@ -133,7 +151,6 @@ angular.module('ui.scroll.grid', [])
133151
}
134152
row[index] = cell;
135153

136-
// this.applyCss(cell, columns[index].layout.css);
137154
return index++;
138155
}
139156
return -1;

0 commit comments

Comments
 (0)