I am currently using Kendo Mobile, and Kendo MVVM to create a native looking browser app. I am using Kendos source and template binding, and I am trying to do something very simple, but cant seem to figure it out. What I want to do is push a new item to my already existing array which works, but I would like the item to go to the top of the list not the bottom. Is there a way to reorder a kendo array once I have pushed to it, or can I explicitly tell my item to push to the top.
Here is my jquery which works, but its pushing to the bottom I want it at the top.
newsfeedvm.get("posts").push({
visibleDelete: false,
myPost: data.IsMine,
auththemecolor: { defaultC: data.DefaultColor, lightC: data.LightColor, darkC: data.DarkColor, },
authpicture: data.AuthorURL,
authdisplayname: data.PostDisplayName,
posttime: data.DisplayTime,
postcontent: data.PostContent,
numberComments: data.CommentCount,
postId: data.Id
});
If newsfeedvm.get("posts")
is returning a regular Array, you can try the unshift
method. It basically does the same thing as push
, except it adds the item to the beginning of the array. Documentation here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
Kendo observable arrays seem to support it as well:
http://docs.telerik.com/kendo-ui/api/framework/observablearray#methods-unshift