Meteor pagination issue

Hello,
I am having issues with pagination I’ve implemented. Pagination works based on server-sided publish skip & limit filter.

Issue #1.
If I perform a specific user search the very first page will be blank.

At that state skip is set to 0, limit is always 20.

If I perform a find().fetch() I get 20 elements, but they are all for a different user.

Issue #2 Me going to next page (skip+10) gives me a few more elements

Doing it again gives even more results

and finally being out of data, and going to next page just removes 10 results, leaving 10 shown

This is a very odd behavior.
Server-sided publish

Meteor.publish('overtime', function(opt){
if (!Roles.userIsInRole(this.userId, 'admin')) {
return Overtime.find({userId: this.userId}, opt);
} else {
return Overtime.find({}, opt);
}
});

Client-sided subscription

var defaultSkipStep = 10;
var defaultLimit = 20;
Template.triphtml.onCreated(function(){
 var instance = this;
 Session.set('limit',defaultLimit);
 instance.autorun(function(){


instance.subscribe('overtime', {skip:(Session.get('overSkip')||0), limit:(Session.get('limit')||defaultLimit), sort: {createdAt: -1}});
instance.subscribe('trips', {skip:(Session.get('tripSkip')||0), limit:(Session.get('limit')||defaultLimit), sort: {createdAt: -1}});
});

Next page click event

"click .nxtpage_over": function(event, template){
Session.set('overSkip', (Session.get('overSkip') || 0) + defaultSkipStep);
Session.set('limit', 20);
},

Submit event

'submit .adminHistoryOForm': function(event, template){
event.preventDefault();
adminHistoryOMonth.set(event.target.filterMonth.value);
adminHistoryOYear.set(event.target.filterYear.value);
adminHistoryOCorp.set(event.target.filterClient.value);
adminHistoryOComment.set(event.target.filterComment.value);
adminHistoryOUser.set(event.target.filterUser.value);
adminHistoryOCar.set(event.target.filterCar.value);
adminHistoryOAct.set(event.target.filterAct.value);


//IGNORE THIS! THIS IS A HOTFIX
if(adminHistoryOUser.get() != Meteor.userId() && adminHistoryOUser.get() != null && adminHistoryOUser.get() != "")
Session.set('overSkip',  0 + defaultSkipStep);
else
Session.set('overSkip', 0);



},

Query that user sees
main.js (client)

manOverHistory: function(){
  let monthSelected = adminHistoryOMonth.get();
  let yearSelected = adminHistoryOYear.get();
  let companySelected = adminHistoryOCorp.get();
  let commentSelected = adminHistoryOComment.get();
  let userSelected = adminHistoryOUser.get();
  let carSelected = adminHistoryOCar.get();
  let actSelected = adminHistoryOAct.get();
const moExpr = monthSelected != "0"? {"month": { $eq: monthSelected}} : {};
const yearExpr = yearSelected != ""? {"year": {$eq: yearSelected}} : {};
const corpExpr = companySelected != ""? {"client": {$eq: companySelected}} : {};
const carExpr = carSelected != ""? {"carNum": {$eq: carSelected}} : {};
const uFilterExpr = userSelected != ""? {"userId": {$eq: userSelected}} : {};
const actExpr = actSelected != ""? {"actnumb": {$eq: actSelected}} : {};
const commentExpr = commentSelected != ""? {"comment": {$regex: commentSelected}} : {};
const allExpr = Object.assign({}, uFilterExpr, yearExpr, moExpr, corpExpr, actExpr, carExpr, commentExpr); 
 adminOverExport = Overtime.find(allExpr, {sort: {createdAt: -1}});

currSearchCount.set(Overtime.find(allExpr, {sort: {createdAt: -1}}).count());



console.log("Count is "+currSearchCount.get()+" and "+Session.get('overSkip') );

return Overtime.find(allExpr, {sort: {createdAt: -1}, limit:1000});


},

html

      {{#each manOverHistory}}
      <tr>
        <td>{{day}}.{{month}}.{{year}}</td>
        <td>{{getName userId}}</td>
        <td>{{carNum}}</td>
        <td>{{client}}</td>
        <td>{{dist}} KM</td>
        <td>{{cost}}€</td>
        <td style="text-align:right;width:60px;">{{fixed odometer}}</td>
        <td>{{actnumb}}</td>
        <td>{{fixTrans transover}}</td>
        <td>{{worknorm}} h</td>
        <td>{{workover}} h</td>
        <td>{{comment}}</td>
        <td><a style="text-decoration: inherit;color:inherit;cursor:pointer;" class="delete-over"><span class="glyphicon glyphicon-trash"></span></a></td>
      </tr> 
    {{/each}}
       
        </tbody>
      </table>
          <span>  {{countLimit}} </span>

Any idea how to make it so that when I perform search for a specific user I get all 20 results just for that user, and next page gives me NEXT 20 elements, not showing any one the 20 I’ve just seen.

1 Like