@@ -112,9 +112,18 @@ class VList : Reactor.Component
112112
113113
114114 function resetPaddings() {
115- // set paddings so scrollbar will reflect the reality
116- this.style[#padding-top] = px(this.swIndex * this.itemHeight);
117- this.style[#padding-bottom] = px(Integer.max(0,this.recordset.length - this.swIndex - this.swLength) * this.itemHeight);
115+ var top = this.swIndex * this.itemHeight;
116+ const middle = this.swLength * this.itemHeight;
117+ const total = this.recordset.length * this.itemHeight;
118+ var bottom = total - middle - top;
119+ if( bottom < 0 ) {
120+ bottom = 0;
121+ top = Integer.max(0,total - middle);
122+ } else if(bottom + top + middle < total)
123+ bottom = top = 0;
124+ this.style[#padding-top] = px(top);
125+ this.style[#padding-bottom] = px(bottom);
126+ Element.update.call(this); // use original Element.update method.
118127 }
119128
120129 function isSelected(record) {
@@ -198,7 +207,7 @@ class VList : Reactor.Component
198207 function navigateTo(record) {
199208 this.currentRecord = record;
200209 if(record) {
201- var recordNo = this.recordset.indexOf(v );
210+ var recordNo = this.recordset.indexOf(record );
202211 if( recordNo < 0 ) return;
203212 this.scrollToRecord(recordNo);
204213 }
@@ -225,10 +234,15 @@ class VTableBody : VList
225234 function render() {
226235 var items = [];
227236 var {recordview, recordset, swIndex, swLength} = this;
237+
238+ if((swIndex + swLength) > recordset.length )
239+ swIndex = this.swIndex = Integer.max(0,recordset.length - swLength);
240+
228241 var end = Integer.min(recordset.length,swIndex + swLength);
229242 for( var i = swIndex; i < end; ++i )
230243 items.push( recordview.call(this,recordset[i],i) );
231244 //debug log: swIndex, swLength, end, items.length;
245+ //debug stacktrace;
232246 return <tbody>{items}</tbody>;
233247 }
234248}
@@ -256,12 +270,12 @@ class VTable: Reactor.Component
256270 assert typeof this.recordview == #function;
257271
258272 this.recordsForView();
259-
260273 }
261274
262275 function update(state = null) {
263276 super.update(state);
264277 this.recordsForView();
278+ this.vtbody.post(this.vtbody.resetPaddings);
265279 }
266280
267281 function render() {
@@ -315,6 +329,7 @@ class VTable: Reactor.Component
315329 return rs2view;
316330 }
317331 rs2view.sort(comparator);
332+
318333 return rs2view;
319334 }
320335
0 commit comments