› Forums › Classic DFFS › Next and previous item by ID
- This topic has 8 replies, 3 voices, and was last updated 5 years, 11 months ago by Alexander Bautz.
-
AuthorPosts
-
-
May 25, 2016 at 10:29 #11751Zaruba.IvanParticipant
Hello Alexander,
is it possible to add buttons for next and previous items from the list? Could be sorted by ID. I would like it for dispform and editform.Thank You
Ivan -
May 31, 2016 at 06:51 #11801Alexander BautzKeymaster
Hi,
This code will work if you don’t have any holes in your number series (no deleted list items). Add this to a HTML section in DFFS:<input type="button" onclick="traverseListElements(false)" value="Previous item" /><input type="button" onclick="traverseListElements(true)" value="Next item" />
And put this in the Custom JS:
function traverseListElements(up){ var id = Number(GetUrlKeyValue("ID")), url; if(up){ url = location.pathname+"?ID="+(id+1); }else{ url= location.pathname+"?ID="+(id-1); } if(GetUrlKeyValue("IsDlg") === "1"){ url += "&IsDlg=1"; } location.href = url; }
Alexander
-
May 31, 2016 at 08:01 #11807Zaruba.IvanParticipant
Hi Alexander,
excellent work, that’s what I (and users of course) dreamed about.
Thank you!
Ivan
-
April 6, 2018 at 22:23 #20479Brandon W GreenParticipant
Hate to resurrect an old thread but it is applicable to my request.
Can this same logic be applied to a specific view rather than by ID?
-
April 7, 2018 at 12:28 #20485Alexander BautzKeymaster
Not sure what you mean by view – are you in a form enhanced with DFFS, or in a list view?
Alexander
-
April 10, 2018 at 20:08 #20518Brandon W GreenParticipant
Display form enhanced by DFFS that is being accessed from a specific list view. This view only display list items based on specific column data.
Remedial Example: Status field with Open, Pending, Completed
Display form is opened from a list view of items where Status = Open
Next / Previous button will navigate through those items *only* rather than by ID increment.
-
April 17, 2018 at 18:53 #20591Alexander BautzKeymaster
Sorry for the late reply. You can do it like this:
var arrOfIDsInView = []; var res = spjs.utility.queryItems({ "listName": _spPageContextInfo.pageListId, "viewName": "{8E016900-8594-45D0-8837-4AFD952C3375}", "viewFields": ["ID"] }); jQuery.each(res.items, function (i, item) { arrOfIDsInView.push(item.ID); }); function traverseListElements(up) { var id = GetUrlKeyValue("ID"), newId, url; if (up) { newId = arrOfIDsInView[jQuery.inArray(id, arrOfIDsInView) + 1]; } else { newId = arrOfIDsInView[jQuery.inArray(id, arrOfIDsInView) - 1]; } if(newId !== undefined){ url = location.pathname + "?ID=" + newId; if (GetUrlKeyValue("IsDlg") === "1") { url += "&IsDlg=1"; } location.href = url; }else{ alert("No item found"); } }
You must replace “{8E016900-8594-45D0-8837-4AFD952C3375}” with the view GUID of your list view. To find it, you can bring up the dev console (hit F12) when you look at the list view, and then type in this:
ctx.view
Alexander
- This reply was modified 5 years, 11 months ago by Alexander Bautz. Reason: fixed code snippet
-
April 19, 2018 at 11:43 #20628Zaruba.IvanParticipant
Hi,
I have a lot of document libraries, and I need to traverse documents and edit custom fields in EditForms. Can I get GUID of the current list view as variable?var res = spjs.utility.queryItems({ "listName": _spPageContextInfo.pageListId, "viewName": "{8E016900-8594-45D0-8837-4AFD952C3375}", "viewFields": ["ID"] });
Thank You.
Ivan
-
April 24, 2018 at 18:02 #20647Alexander BautzKeymaster
Yes, use ctx.view like this:
var res = spjs.utility.queryItems({ "listName": _spPageContextInfo.pageListId, "viewName": ctx.view, "viewFields": ["ID"] });
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.