none
"/_api/web/lists/getbytitle('listname')/items?$select=ID,Title,URL,OrderID&?orderby=OrderID asc" renders the orderId as string

    Question

  • when I execute this method I expect the returned results to be sorted by OrderId (which is a number field). However I believe the rendered results are in string and the order is messed up. the Order Id of 10 jumps on top below Order Id of two. How can I force it to render the orderId as a number so that the order is:

    1 2 3 4 5 6 7 8 9 10?


    faye fouladi

    Thursday, January 10, 2019 9:07 PM

Answers

  • Hi SharePointTeck,

    Tested the Rest EndPoint  with code below and it is working:

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
      $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('TestList11')/items?$select=ID,Title,OrderID&?orderby=OrderID asc",
                type: "GET",
                headers: {"Accept": "application/json;odata=verbose"},        
                success: function(data){
                   $.each(data.d.results, function(){
                                          
                  console.log(this.OrderID);
                  console.log(Number.isInteger(this.OrderID));
                    });                
                },
                error: function(errorMsg){
                    console.log(errorMsg);
                }
            });   
    </script>

    Sort with asc order and use Number.isInteger to check if it is a int number:

    This is the test list data:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by SharePointTeck Tuesday, January 15, 2019 6:14 PM
    Friday, January 11, 2019 7:37 AM
  • Hi,

    Bind <li> tag with Order ID like this:

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
      var item="<ul class='side-nav-link'>";
      $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('TestList11')/items?$select=ID,Title,OrderID&?orderby=OrderID asc",
                type: "GET",
                headers: {"Accept": "application/json;odata=verbose"},        
                success: function(data){
                   $.each(data.d.results, function(){
                        console.log(this.OrderID);
                        item +="<li>" + this.OrderID + "</li>";                  
                    });  
                    item += "</ul>";
                    console.log(item); 
                    $("#navigation").html(item);             
                },
                error: function(errorMsg){
                    console.log(errorMsg);
                }
            });   
    </script>
    <div id="navigation"></div>
    

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, January 14, 2019 3:21 AM

All replies

  • "/_api/web/lists/getbytitle('listname')/items?$select=ID,Title,URL,OrderID&?orderby=OrderID asc"

    First, is the syntax correct? I think it should be:

    "/_api/web/lists/getbytitle('listname')/items?$select=ID,Title,URL,OrderID&$orderby=OrderID asc"

    When doing programmatically, I even go so far as to replace the blanks with plus(+).

    "/_api/web/lists/getbytitle('listname')/items?$select=ID,Title,URL,OrderID&$orderby=OrderID+asc"


    Steve Clark, MCTS
    Easy Bins Roll-off Dumpster Rentals in Northern VA
    Specializing in:
    Driveway-sized, roll-off dumpster rentals in Fairfax VA | Dumpster Rentals for Junk Hauling in Springfield VA
    Roll-off Rental Dumpsters in Annandale, VA

    Friday, January 11, 2019 5:16 AM
  • Hi SharePointTeck,

    Tested the Rest EndPoint  with code below and it is working:

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
      $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('TestList11')/items?$select=ID,Title,OrderID&?orderby=OrderID asc",
                type: "GET",
                headers: {"Accept": "application/json;odata=verbose"},        
                success: function(data){
                   $.each(data.d.results, function(){
                                          
                  console.log(this.OrderID);
                  console.log(Number.isInteger(this.OrderID));
                    });                
                },
                error: function(errorMsg){
                    console.log(errorMsg);
                }
            });   
    </script>

    Sort with asc order and use Number.isInteger to check if it is a int number:

    This is the test list data:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by SharePointTeck Tuesday, January 15, 2019 6:14 PM
    Friday, January 11, 2019 7:37 AM
  • I will fix the code and see if it does the job. I will let you know.

    Thanks


    faye fouladi

    Friday, January 11, 2019 2:25 PM
  • This actually did not work in my case because I am building a left hand side navigation wit data returned and 

     class="side-nav-link" id="liFrm=10"

    is placed at the second order. this is what I need to fix.

    Any idea?


    faye fouladi

    Friday, January 11, 2019 6:03 PM
  • I tested the REST service and it worked. However, I am building a html from the rows and I need to order the  html based on the ID of the  <li> tags which is OrderID. How can I do that. It appears the order gets messed up when I build my html from the rows.

    Thanks


    faye fouladi


    • Edited by SharePointTeck Saturday, January 12, 2019 1:32 AM incorrect synthx
    Saturday, January 12, 2019 1:26 AM
  • Hi,

    Bind <li> tag with Order ID like this:

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
      var item="<ul class='side-nav-link'>";
      $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('TestList11')/items?$select=ID,Title,OrderID&?orderby=OrderID asc",
                type: "GET",
                headers: {"Accept": "application/json;odata=verbose"},        
                success: function(data){
                   $.each(data.d.results, function(){
                        console.log(this.OrderID);
                        item +="<li>" + this.OrderID + "</li>";                  
                    });  
                    item += "</ul>";
                    console.log(item); 
                    $("#navigation").html(item);             
                },
                error: function(errorMsg){
                    console.log(errorMsg);
                }
            });   
    </script>
    <div id="navigation"></div>
    

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, January 14, 2019 3:21 AM