Home CMDB Portal

Sorting\Ordering OData Views

Sean_TerrySean_Terry Customer Advanced IT Monkey ✭✭✭

If you have an OData table, is there an easy way to order the contents via a specific column?

I have a custom view for Business Services with the filter: ?$filter=(StatusId ne null).

Just wondering if there is a simple way of adding a sort function on the DisplayName.

Best Answer

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Accepted Answer

    @Sean_Terry - You can use the odata $orderby operator. I just tried this in one of my widgets. I ordered by Title by adding this to the Query String: ?$orderby=Title

    You can string them together with the & sign:

    ?$filter=(Title ne null)&$orderby=Title

    There is a lot of good info about odata operations here: https://www.odata.org/documentation/odata-version-2-0/uri-conventions/ They may not all work with the query string in the widget, but it's a good guide for figuring out what's available.

Answers

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    @Sean_Terry - Sorting in the grid works for me in an odata widget. Is it not working for you or are you just talking about pre-sorting?

  • Sean_TerrySean_Terry Customer Advanced IT Monkey ✭✭✭
    edited January 6

    @Justin_Workman Thanks for the reply. Pre sorting if that's possible? I've grabbed the filter from the out of the box CMDB pages, but I wasn't sure if another command can be bolted on to pre sort?

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Accepted Answer

    @Sean_Terry - You can use the odata $orderby operator. I just tried this in one of my widgets. I ordered by Title by adding this to the Query String: ?$orderby=Title

    You can string them together with the & sign:

    ?$filter=(Title ne null)&$orderby=Title

    There is a lot of good info about odata operations here: https://www.odata.org/documentation/odata-version-2-0/uri-conventions/ They may not all work with the query string in the widget, but it's a good guide for figuring out what's available.

  • Sean_TerrySean_Terry Customer Advanced IT Monkey ✭✭✭

    @Justin_Workman Thank you!! Works a treat.

Sign In or Register to comment.