1

In a web application I am rendering a list of documents coming from a Sharepoint 2013 Document Library (the number of documents can vary, approximately, from 5 to 50). The user needs to be able to sort this documents from inside the application, and save the new order. Now, what is the best approach to achieve this?

So far, I have created a "Position" column in the document library that accepts integer numbers, and sort the documents by the value in that column (e.g., from 1 to 30). The problem is, when a user changes the position of a document in the application, I have to update the values of the "Position" column for all the other documents as well, so that the new position gets registered for each one.

Following this approach, I should iterate through all the documents IDs I have stored in my application, and for each iteration send an ajax post request like the following:

$.ajax({
    url: url + "/Items(" + id + ")",
    type: "POST",
    data: data,
    headers: {
        Accept: "application/json;odata=verbose",
        "Content-Type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "IF-MATCH": "*",
        "X-Http-Method": "MERGE"
    }
});

Is there an alternative to send so many ajax requests? Any other approach on how to handle this problem, by using only REST API? I have found this question, but I do not know how to adapt it for my case.

1 Answer 1

2

Following are the ways as per my understanding, let me know if any would be useful for your case:

  1. Lists.UpdateListItems Method. This might be very outdated solution, but you can batch your updates since you are using SP 2013.

  2. Better way would be to use another list (configuration list), and store the document id, position values as an array.

    a. In this way you don't have to update each documents in the document library if user reorders. You will have to perform 2 calls to SharePoint, 1st to get the document list and 2nd to get their orders from your configuration list.

    b. During reorder operation you will just have to post the update to your configuration list.

    c. This solution will work even if you move to higher version of SharePoint and even to SharePoint Online.

1
  • I guess using the list is the best option, you are right. Thanks! Apr 27, 2020 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.