Skip to content

Commit 17d8f74

Browse files
committed
Reactor vlist nviagetTo fix
1 parent 9c6b456 commit 17d8f74

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

samples/+reactor/components/vlist/vlist.htm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,32 @@
2929
:checked={this.isSelected(record)}>This is an item # {index}.</li>;
3030
}
3131

32+
var vlist;
33+
3234
$(main).content(
3335
<VList
3436
multiselect
3537
recordset={records}
36-
recordview={renderRecord} />);
38+
recordview={renderRecord}
39+
@{vlist} />);
40+
41+
event click $(#go) {
42+
var rn = $(#record-number).value;
43+
vlist.navigateTo(records[rn]);
44+
45+
}
3746

3847
</script>
3948
</head>
4049
<body>
4150
<p>Demo of simple virtual list component &lt;VList>.</p>
4251
<p>The caller shall suply record view producer function.</p>
4352
<p>The list supports multiselection (CTRL+CLICK).</p>
53+
54+
<form>
55+
Record <input|integer #record-number min=0 max=1000 novalue="#" step="10" /> <button#go>Go</button>
56+
</form>
57+
4458
<main></main>
4559
</body>
4660
</html>

samples/+reactor/components/vlist/vlist.tis

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)