Meteor-Community-Packages / Meteor-Community-Packages/meteor-tabular
Problem pagination in joined collections: template does NOT load data
- Dominant language
- JavaScript
- Stars
- 360
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
Hi guys,
I am playing around with client-side joins in combination with aldeed:tabular and reywood:publish-composite and ran into a problem getting custom columnTemplates to work.
The problem is that in the below example the column `Template.commentsColumn` does NOT refresh correctly when paginating. Strangly `postCommentsBadAssButWorks` shows the correct data. So I am guessing it is NOT the publication, but the reactivity within the template?
Does anyone have an idea what I am doing wrong?
This is a video I did showing the problem
https://www.youtube.com/watch?v=rVsEUsc9TTU
This is a code-excerpt:
**Table Definition**
```
import { Authors, Comments, Posts } from '/lib/collection.js'
export const PostsTable = new Tabular.Table({
name: 'Posts',
collection: Posts,
pub: 'tabular.posts',
extraFields: [
'authorId',
'commentIds',
],
pageLength: 30,
columns: [
{data: '_id', title: '#ID'},
{data: 'post', title: 'Post'},
{data: 'postAuthor()', title: 'Author Name'},
{
title: 'CommentsIds',
data: 'this', // set data for sort-option & template-context!
tmpl: Meteor.isClient && Template.commentIdsColumn,
tmplContext: function (rowData) {
return {
doc: rowData,
};
}
},
{data: 'postCommentsBadAssButWorks()', title: 'Comments Collection-Helper (WORKS)'},
{
title: 'Comments CustomColumnTemplate (PROBLEM)',
// data: 'this', // set data for sort-option & template-context!
tmpl: Meteor.isClient && Template.commentsColumn,
// tmplContext: function (rowData) {
// return {
// doc: rowData,
// };
// }
},
]
})
```
**Collection Helper**
```
// COLLECTION HELPER for tabular!!!
Posts.helpers({
postAuthor: function() {
return Authors.findOne(this.authorId).author
},
postComments: function() {
// This does NOT seem to RELOAD in the tempalte
log(`postComments collection helper`)
// return Comments.find({_id: { $in: this.commentIds } }).fetch() does NOT work either
return Comments.find({_id: { $in: this.commentIds } })
},
postCommentsBadAssButWorks: function() {
// This works but is BAAD
let html = '
- '
- ${comment.comment} `
Comments.find({_id: { $in: this.commentIds } }).forEach(function (comment) {
html += `
})
html += '
return html
},
})
```
**Template**
```
- {{this.comment}}
{{#each this.postComments}}
{{/each}}
```
Contributor guide
Research direction
Start with the PostsTable definition, the postComments collection helper, and the commentsColumn template shown in the issue. Reproduce pagination with the joined collections and inspect whether the template receives updated row data. Done means the custom commentsColumn displays the comments for the current page after pagination, consistently with the working helper output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100