2

I have created a BC WebApp using the BC Open Platform API's for the back end and everything appears to work fine including rendering the list of items in a sort order of one of my custom fields.

Here is an example of what works on the back end.

var items = new BCAPI.Models.WebApp.ItemCollection(WEBAPP_NAME);
items.fetch({
    order: "MyCustomField",
    skip: 0,
    limit: 1000,
    success: onWebpAppListFetch,
    error: onAPIError
});

How do I render this list on the front end sorted by one of my custom fields? Here is an example of what I am trying to use on the front end, but it does not order or sort this way.

{module_webapps order="MyCustomField" render="collection" template="/_System/apps/cms-sports-club-manager/club-rooms/layouts/club_rooms_collection.tpl" id="cms-club-roomsx" filter="all"}

Is there something that I am overlooking, or do I need to approach this in my own manual way? Perhaps I could render the list into an array, sort the array and then iterate through that to render the front end listing? The template file uses Liquid to iterate through the collection and render the HTML. Can I define an array variable, fill the array, sort the array and iterate through the array again in that same template file?

Another possibility perhaps is to output all webapp items into a JSON file each time a user creates/edits an item (from the back end), and then use the {module_json} feature on the front end to read that JSON file which "should" allow me to sort it.

Any advice on what to do (as well as what NOT to do) would be appreciated.

L84
  • 45,514
  • 58
  • 177
  • 257
David
  • 159
  • 1
  • 3
  • 13
  • There is no `order=" "` in the `module_webapps` so that should be removed. Your best option is to use Liquid to sort the web app field, however, I am unsure of the code to do this. – L84 Sep 13 '15 at 02:34

1 Answers1

0

I have found one possible answer, but I am not sure it is the best way to do this.

I have implemented a script which performs the following steps:

  1. Create an array holding all items (unsorted at this point)
  2. Sort the array using any custom field
  3. Iterate through the sorted array and document.write() each one

I have tested this a fair bit and it seems to do exactly what I want, however I have not marked this as the correct answer just yet as I would still like to find a "better" way than needing to resort to the above manual work.

David
  • 159
  • 1
  • 3
  • 13