Sorting URL Change formatting

3 posts, 0 answers
  1. Shannon
    Shannon avatar
    6 posts
    Member since:
    Jul 2014

    Posted 25 Jan 2015 Link to this post

    I need to be able to have a GET request as follows:  

    http://localhost:8080/api/leads?page=2&size=20&sort=firstName,desc -> or asc


    This is for Server Side sorting for a Spring Data Rest project.  Currently the Sorting portion is showing up as an array.  How do you change the way the sorting URL is formed?
  2. Shannon
    Shannon avatar
    6 posts
    Member since:
    Jul 2014

    Posted 25 Jan 2015 Link to this post

    Have something that is working now, not sure if this is good or bad.  Any comments more than welcome.

    <script>
        function parameterMap(data, operation) {
     
            if (operation == "read") {
     
                if (data.sort && data.sort.length > 0) {
     
                    var values = {};
                    values["page"] = data.page;
                    values["size"] = data.pageSize;
                    values["sort"] = data.sort[0]['field'] + ',' + data.sort[0]['dir'];
                    return values;
     
                }
     
            }
     
        }
    </script>
  3. UI for ASP.NET AJAX banner
  4. Shannon
    Shannon avatar
    6 posts
    Member since:
    Jul 2014

    Posted 25 Jan 2015 in reply to Shannon Link to this post

    Found that the above worked for sorting but killed pagination.  Below if the fix for both.

    <script>
        function parameterMap(data, operation) {
     
            if (operation == "read") {
     
                if (data.sort && data.sort.length > 0) {
     
                    var values = {};
                    values["page"] = 1;
                    values["size"] = data.pageSize;
                    values["sort"] = data.sort[0]['field'] + ',' + data.sort[0]['dir'];
                    return values;
     
                } else {
     
                    var values = {};
                    values["page"] = data.page;
                    values["size"] = data.pageSize;
                    return values;
     
                }
     
            }
     
        }
    </script>
Back to Top