Dynamic add element to the top of the page

nl pkr

PROBLEM: I have table with tr that have data from table, When I insert element in Mongo and post it on my page, element added on the bottom of the table

    Posts = new Mongo.Collection('posts');

    Meteor.publish('allPosts', function(){
        return Posts.find({}, { sort: { date: -1 }} );
    });

    Meteor.subscribe("allPosts");

    Posts.insert({
      date: 1
    })

    Posts.insert({
      date: 2
    })

Posts.insert({
      date: 3
    })
<table class=" table">
      {{#each posts}}
          {{> postJobs}}
      {{/each}}
</table>

<template name="postJobs">
  <tr class="smallInfo">
    <td>{{date}}</td>
  </tr>
</template>

In DOM I have:

    <table>
      <tr>
        <td>1</td> // must be 3
      </tr>
      <tr>
        <td>2</td> // must be 2
      </tr>
<tr>
        <td>3</td> // must be 1
      </tr>
    </table>

All my last inserts must add to the top of my page (table)

EDIT : My problem with dynamic insert in collection (and i know about -1 gramatik mistake) EXAMPLE :

Meteor.startup(function(){
  Meteor.setTimeout(function(){Test("10");}, 1000);
  function Test(x)
{
  Posts.insert( {
    submitDate: moment().format()
  });
}
  Meteor.setTimeout(function(){Test("10");}, 10000);

If i sort by submitDate it will show like :

<tr><td>10-10-10</td></tr> // must be 10-10-20
<tr><td>10-10-20</td></tr> // must be 10-10-10

BUT when i refresh my page(F5) all ok

<tr><td>10-10-20</td></tr> 
<tr><td>10-10-10</td></tr> 
Tom Freudenberg

Why do you not sort descending?

{sort: { date: -1 } }

Cheers, Tom

UPDATE:

You can find a live example at a MeteorPad I prepared:

http://meteorpad.com/pad/Ba5DTe94NjFi3ZTPA/Playground_Flow-Router_Chat

You have to do the sort on the client side not within the publish method.

This is why you get first time sorted but then just as inserted returns.

If you do the sort on client side find() the minimongo will do it on each new document.

Hope this helps for you. Tom

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bring an element to top of the page even if the page does not scroll

From Dev

Add class when element hits top of page AND remove class when element reaches bottom of parent

From Dev

How to add the Cart button on top of the page in Woocommerce?

From Dev

Fixing an element when it reaches the top of the page

From Dev

How to add Html element to dynamic list in jquery

From Dev

AngularJS: Add a loader element to top of DOM

From Dev

Add class when element reaches top of viewport

From Dev

Keep element fixed at top of page on scroll

From Dev

How to dynamic add and remove element by jQuery?

From Dev

Add element on top of image dynamically

From Dev

Add unique element to ArrayList with "dynamic" suffix

From Dev

Add dynamic content on ccavenue page using php

From Dev

Add JavaScript to dynamic (plugin-generated) element

From Dev

How to add Html element to dynamic list in jquery

From Dev

How To Make Element Static With Dynamic Page Content

From Dev

Add a <tr> element to dynamic table, dynamically without a page refresh, php jquery

From Dev

How to add 10 pixels to a dynamic top position in CSS using SASS

From Dev

Add element on top of image dynamically

From Dev

How add a top-down page border?

From Dev

Add class to body on dynamic element, remove after clicking again anywhere on page

From Dev

Override postion top of pseudo element on certain page

From Dev

Add class to element if at top of page and user scrolls up

From Dev

How to add an element on top of an image in HTML?

From Dev

How to add dynamic element jquery?

From Dev

Add element to bottom of page

From Dev

Javascript add element to a dynamic div

From Dev

properly scroll element to the top of the page using javascript

From Dev

Add banner image on both top and bottom of the page

From Dev

Tree View Dynamic Absolute Element (top, left) in Vue Js

Related Related

  1. 1

    Bring an element to top of the page even if the page does not scroll

  2. 2

    Add class when element hits top of page AND remove class when element reaches bottom of parent

  3. 3

    How to add the Cart button on top of the page in Woocommerce?

  4. 4

    Fixing an element when it reaches the top of the page

  5. 5

    How to add Html element to dynamic list in jquery

  6. 6

    AngularJS: Add a loader element to top of DOM

  7. 7

    Add class when element reaches top of viewport

  8. 8

    Keep element fixed at top of page on scroll

  9. 9

    How to dynamic add and remove element by jQuery?

  10. 10

    Add element on top of image dynamically

  11. 11

    Add unique element to ArrayList with "dynamic" suffix

  12. 12

    Add dynamic content on ccavenue page using php

  13. 13

    Add JavaScript to dynamic (plugin-generated) element

  14. 14

    How to add Html element to dynamic list in jquery

  15. 15

    How To Make Element Static With Dynamic Page Content

  16. 16

    Add a <tr> element to dynamic table, dynamically without a page refresh, php jquery

  17. 17

    How to add 10 pixels to a dynamic top position in CSS using SASS

  18. 18

    Add element on top of image dynamically

  19. 19

    How add a top-down page border?

  20. 20

    Add class to body on dynamic element, remove after clicking again anywhere on page

  21. 21

    Override postion top of pseudo element on certain page

  22. 22

    Add class to element if at top of page and user scrolls up

  23. 23

    How to add an element on top of an image in HTML?

  24. 24

    How to add dynamic element jquery?

  25. 25

    Add element to bottom of page

  26. 26

    Javascript add element to a dynamic div

  27. 27

    properly scroll element to the top of the page using javascript

  28. 28

    Add banner image on both top and bottom of the page

  29. 29

    Tree View Dynamic Absolute Element (top, left) in Vue Js

HotTag

Archive